PDA

View Full Version : QPushButton::drawButtonLabel problem



batileon
9th July 2008, 10:14
I am now porting codes from QT3 to QT4
And I found that in QT3, QPushButton has a virtual protected member drawButtonLabel which is inherited from QButton.

void QButton::drawButtonLabel ( QPainter * ) [virtual protected]

However I can't find any related member in QT 4............
Can anyone help me with this?

wysota
9th July 2008, 11:08
What do you need it for? Qt4 does it through use of QStyle::drawControl() with CE_PushButtonLabel

batileon
9th July 2008, 11:43
Actually I used this function to do the word wrap on QButton in QT3.
Since this drawButtonLabel is virtual and we used this to do the word wrap reimplementation.

However after porting to QT4, I found that the text on QButton is no longer wrapped.
So what should I so?

batileon
10th July 2008, 06:37
Since I m porting old code to QT4.
and the original code made use of the virtual function `drawButtonLabel` to draw the text and did the word wrapping there.
So I m looking for something similar to complete the task......

can anyone help me please???:(

JimDaniel
10th July 2008, 07:45
Why can't you just use QPushButton::setText(const QString & text); ? If all you want to do is draw label text, that's what it's for. But if not, maybe this can work....

Say you override the QPushButton's paint event, then you can call QFontMetrics::boundingRect(const QRect & rect, int flags, const QString & text, int tabStops = 0, int * tabArray = 0 ) ;

Set Qt::TextWordWrap as a flag, and pass in the text you want to draw as well as the button's rect, and it will return you a QRect you can use to draw your text (with word wrap) in that space. Then you draw it with QPainter::drawText(const QRect & rectangle, int flags, const QString & text, QRect * boundingRect = 0);

Or maybe you can use style sheets. I'm not too familiar with them myself, but they seem pretty versatile.

batileon
10th July 2008, 08:47
actually I m doing something similar in the virtual function.............
Since the `drawButtonLabel` should be invoked automatically, that's why I needa find something alike to invoke the process