Results 1 to 7 of 7

Thread: ampersand showing in QLabel

  1. #1
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default ampersand showing in QLabel

    hello

    In QLabel instead of showing a letter underlined, I see the ampersand sign.
    for example:
    Qt Code:
    1. QLineEdit *initiator = new QLineEdit(this);
    2. QLabel *initiatorL = new QLabel("&initiator:", this);
    3. initiator->setBuddy(initiatorL)
    To copy to clipboard, switch view to plain text mode 
    Show in my widget as: "&initiator:" with the ampersand.

    How can I make Qlabel display it correctly, as an underlined letter?
    Last edited by dave; 5th November 2006 at 00:47. Reason: grammar

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ampersand showing in QLabel

    Quote Originally Posted by dave View Post
    initiator->setBuddy(initiatorL)
    Shouldn't it be:
    Qt Code:
    1. initiatorL->setBuddy(initiator)
    To copy to clipboard, switch view to plain text mode 
    ?

  3. #3
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ampersand showing in QLabel

    You're right, of course jacek.
    should be:
    Qt Code:
    1. QLineEdit *initiator = new QLineEdit(this);
    2. QLabel *initiatorL = new QLabel("&initiator:", this);
    3. initiatorL->setBuddy(initiator)
    To copy to clipboard, switch view to plain text mode 

    Any idea about the problem?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: ampersand showing in QLabel

    Read notes about mnemonic in QLabel::setBuddy().

    Edit: Hmm, just ignore this.. I definitely need some sleep
    Last edited by jpn; 5th November 2006 at 01:15. Reason: updated contents
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Posts
    52
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ampersand showing in QLabel

    I think I found out the reason. Apparently I called setbuddy before setting up the associated widget. Like this:
    Qt Code:
    1. QLabel *initiatorL = new QLabel("&initiator:", this);
    2. initiatorL->setBuddy(initiator);
    3. QLineEdit *initiator = new QLineEdit(this);
    To copy to clipboard, switch view to plain text mode 
    Changing line 2 with 3 fixed the problem. Really should have noticed it...

    But now I have a weird problem. This is the code:
    Qt Code:
    1. initL = new QLabel("&Initiator");
    2. init = new QLineEdit();
    3. initL->setBuddy(init);
    4. init->setValidator(new LSEdgeValidator(init));
    5.  
    6. ruleFL = new QLabel("Production &F");
    7. ruleF = new QLineEdit();
    8. ruleFL->setBuddy(ruleF);
    9. ruleF->setValidator(new LSEdgeValidator(ruleF));
    10.  
    11. rulefL = new QLabel("Production &f");
    12. rulef = new QLineEdit();
    13. rulefL->setBuddy(rulef);
    14. rulef->setValidator(new LSEdgeValidator(rulef));
    To copy to clipboard, switch view to plain text mode 
    And the problem is:
    First: the underline won't show up unless I press the ALT key. Second: Once I do - the underline shows on every QLabel apart from initL - the first QLabel I set up in the code. If I change initL place in the code and put ruleFL first - then ruleFL won't show underlined.
    I'm confused.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ampersand showing in QLabel

    Quote Originally Posted by dave View Post
    First: the underline won't show up unless I press the ALT key.
    This is a windows "feature", probably you can disable it somewhere (for example in theme settings).

  7. #7
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ampersand showing in QLabel

    To add to what Jacek said. Here is a Quote
    Any sufficiently disguised bug is indistinguishable from a feature. -- Rich Kulawiec
    We can't solve problems by using the same kind of thinking we used when we created them

Similar Threads

  1. QLineEdit && QLabel
    By eleanor in forum Newbie
    Replies: 16
    Last Post: 12th November 2006, 18:30
  2. Subclassed QLabel and enterEvent
    By Lykurg in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2006, 07:44
  3. QT4 layout of complex dialog is very slow
    By cboles in forum Qt Programming
    Replies: 15
    Last Post: 28th April 2006, 20:57
  4. table in QLabel
    By Pan Wojtas in forum Qt Programming
    Replies: 19
    Last Post: 13th February 2006, 12:37
  5. QLabel with HTML-style formatting docs?
    By Everall in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2006, 21:01

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.