Results 1 to 5 of 5

Thread: QLabel on a Button

  1. #1
    Join Date
    Jan 2006
    Posts
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QLabel on a Button

    Is it possible to put a qlabel on a qpushbutton (or any button for that matter)??

    I want to present a button that has formatted text, such as (for example):

    "<b>Button Name</b> non-bold text"

    A label seems like the logical solution, but it doesn't seem possible...

    Thanks,
    Chris

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QLabel on a Button

    You could use a label and implement the button functionality by overiding mouseClicked. Another option might be to set a pixmap that contains the rendered text as a pixmap. Not nice, but simple.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Jan 2006
    Location
    South Carolina, USA
    Posts
    34
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel on a Button

    This will place a QLabel on a QPushButton, albeit at the top left corner. You will have to add the code to center it...
    Qt Code:
    1. QPushButton *button = new QPushButton(this);
    2. button->setText("");
    3. QLabel *label = new QLabel(button);
    4. label->setText("<b>Button</b> Test");
    To copy to clipboard, switch view to plain text mode 

    EDIT:
    One thing to keep in mind is that on a regular button when it is clicked the text moves to the right and down a little to help give it that pushed down look... On the above button the text will not move.


    Michael
    Last edited by michael; 12th January 2006 at 03:16.

  4. #4
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: QLabel on a Button

    And is there a function wich change the position of QLabel within
    the button?
    Thanks
    Regards

  5. #5
    Join Date
    Jan 2006
    Posts
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel on a Button

    Okeydoke, that gives me three things to try...

    I'll have a go at overriding mouseClicked first and see what happens...

    Thanks guys!

Similar Threads

  1. button background color when it is clicked
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 9th December 2008, 16:02
  2. Replies: 3
    Last Post: 17th July 2008, 08:43
  3. QLabel ScaledContents ignored by style sheet?
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 27th February 2008, 15:50
  4. question about button
    By narumi in forum Newbie
    Replies: 2
    Last Post: 21st January 2008, 06:44
  5. How can I put a button onto the qLabel?
    By dwlnet in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2007, 10:47

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.