PDA

View Full Version : QLabel on a Button



cwalsh
11th January 2006, 18:50
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

axeljaeger
11th January 2006, 20:44
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.

michael
12th January 2006, 03:10
This will place a QLabel on a QPushButton, albeit at the top left corner. You will have to add the code to center it...


QPushButton *button = new QPushButton(this);
button->setText("");
QLabel *label = new QLabel(button);
label->setText("<b>Button</b> Test");


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

mickey
12th January 2006, 09:42
And is there a function wich change the position of QLabel within
the button?
Thanks

cwalsh
12th January 2006, 17:06
Okeydoke, that gives me three things to try...

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

Thanks guys!