PDA

View Full Version : QLabel vs. QLineEdit with Delegates



moviemax
21st June 2011, 10:16
Hi there,
I would like to display some text data from a model.
As mentioned in "books" or "combowidgetmapper" demo QLineEdit works just out of the box:


...
QLineEdit nameEdit;
...
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->addMapping(nameEdit, 0);



Because I just want to display the text I'm willing to use QLabel instead.
How do I have to derive QLabel that I can use it as QLineEdit


MyLabel namelabel;
...
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->addMapping(nameLabel, 0);


Or in other words why is the signal setText() not enough for QWidgetMapper
regards

wysota
21st June 2011, 10:59
Because QDataWidgetMapper doesn't know which property to use. Use the variant of the addMapping call that takes a property name.

moviemax
21st June 2011, 16:23
thank for your fast reply wysota
but the property name is the same like the object name and using the explicit function doesn`t change anything.
Which property should QDataWidgetMapper use? is there any further documentation?

wysota
21st June 2011, 16:39
but the property name is the same like the object name
No, the property name is "text".

ChiliPalmer
21st June 2011, 22:23
From a design-point of view, using a QLabel to display data might not be ideal. If you are developing an application that is intended to primarily run on windows, you should think about using a read-only QLineEdit without frame. The MSDN Design Guide (http://msdn.microsoft.com/en-us/library/aa511440.aspx) advises to do so for optical reasons, but mainly to give the user the possibility to select and copy the data to the clipboard.

moviemax
21st June 2011, 23:04
@wysota
so you are right with given property "text" it works :

mapper_r1->addMapping( label_row1, 0, "text")
I didn`t get you at first.
@chilli
you are right I could not copy the text, but that is not so bad because there is also a table where users can copy strings from
Thanks all

moviemax
24th June 2011, 06:36
How can I set this thread to solved?

wysota
24th June 2011, 08:36
You can't :)