Results 1 to 8 of 8

Thread: QLabel vs. QLineEdit with Delegates

  1. #1
    Join Date
    Jun 2010
    Location
    Germany, Munich
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QLabel vs. QLineEdit with Delegates

    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:
    Qt Code:
    1. ...
    2. QLineEdit nameEdit;
    3. ...
    4. mapper = new QDataWidgetMapper(this);
    5. mapper->setModel(model);
    6. mapper->addMapping(nameEdit, 0);
    To copy to clipboard, switch view to plain text mode 


    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

    Qt Code:
    1. MyLabel namelabel;
    2. ...
    3. mapper = new QDataWidgetMapper(this);
    4. mapper->setModel(model);
    5. mapper->addMapping(nameLabel, 0);
    To copy to clipboard, switch view to plain text mode 

    Or in other words why is the signal setText() not enough for QWidgetMapper
    regards
    Last edited by wysota; 21st June 2011 at 09:58.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLabel vs. QLineEdit with Delegates

    Because QDataWidgetMapper doesn't know which property to use. Use the variant of the addMapping call that takes a property name.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2010
    Location
    Germany, Munich
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel vs. QLineEdit with Delegates

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLabel vs. QLineEdit with Delegates

    but the property name is the same like the object name
    No, the property name is "text".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Location
    Aachen, Germany
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLabel vs. QLineEdit with Delegates

    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 advises to do so for optical reasons, but mainly to give the user the possibility to select and copy the data to the clipboard.

  6. #6
    Join Date
    Jun 2010
    Location
    Germany, Munich
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel vs. QLineEdit with Delegates

    @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

  7. #7
    Join Date
    Jun 2010
    Location
    Germany, Munich
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel vs. QLineEdit with Delegates

    How can I set this thread to solved?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLabel vs. QLineEdit with Delegates

    You can't
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Which to include QtGui or QLabel, QLineEdit...
    By MIH1406 in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2009, 12:23
  2. Change QLabel to QLineEdit when mousePressEvent happens
    By naoyamakino in forum Qt Programming
    Replies: 2
    Last Post: 16th July 2009, 18:37
  3. Connect QLabel and QLineEdit
    By abbapatris in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2008, 19:00
  4. Replies: 1
    Last Post: 26th November 2006, 09:32
  5. QLineEdit && QLabel
    By eleanor in forum Newbie
    Replies: 16
    Last Post: 12th November 2006, 17:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.