tags:

views:

45

answers:

2

I am instantiating an editable QLabel like so:

QLabel foo("some text");
foo.setTextInteractionFlags(Qt::TextEditorInteraction);

I can click the text and modify it, and the modified text must be in a buffer somewhere, but even after examining the data fields in Qt Creator I don't see where it is:

QString notmodified = foo.text(); // only returns the original text

is the modified text somewhere that I can access it?

EDIT: I think using something else is indeed an easier way, but I'm still interested in knowing the answer to my question.

EDIT: OK, it's been a week. "Answered".

+4  A: 

I would say that even though you can set this flag on a QLabel (the Qt::TextInteractionFlag is used by other widgets than QLabel), it is not designed to be edited.

Why don't you use a QLineEdit ?

Jérôme
Absolutely - this is making life complicated for yourself, and probably the user, since the UI experience will not be sensible, especially in terms of accessibility. If you want editable text, use a QLineEdit. What you might want, is to hide the QLabel and replace it with a QLineEdit when clicked, then restore the QLabel when the QLineEdit loses focus.
James Turner
A: 

For editable text field you have a good choise, QLineEdit or QTextEdit. Use one of these widgets. QLabel is just for labeling.

Narek