I know how to do single color, using style sheet or QPalette, but what can i do when button's text has more that one color?
I know how to do single color, using style sheet or QPalette, but what can i do when button's text has more that one color?
There's a very nice solution here:
http://www.qtcentre.org/threads/3109...160#post145160
Basically, use a label or text document to print the text you want.
Then paint it to a pixmap and use the pixmap on your button.
I've added this to the wiki page:
http://www.qtcentre.org/wiki/index.p...ultiple_colors)
This solution surely works, but you lose the possibility to add a custom icon. I think a better approach would be to alter the paint event and render the text document to the painter. After setting html you just need to update the buttons size. Than you can use the icon and all other functions as normally. A similar project is [WIKI]OrientationButton[/WIKI] which uses the paint event.
You're right.
I'll improve the wiki page.
How to do that if button with pixmap is disabled, icon is not gray?
It is no working..
;code Code:
text.setHtml("<font color = green><b>sometext</b></font>"); pixmap = QPixmap(text.size().toSize()); pixmap.fill(Qt::transparent); text.drawContents(&QPainter(&pixmap), pixmap.rect()); pixmap = QIcon(pixmap).pixmap(pixmap.size(), QIcon::Disabled); button->setIcon(QIcon(pixmap)); leftButtons[i]->setIconSize(pixmap.rect().size())To copy to clipboard, switch view to plain text mode
Resolved
Last edited by somename; 30th May 2010 at 12:07.
Here's an update:
http://www.qtcentre.org/wiki/index.p...ultiple_colors)
Now you can also set an icon.
Since my time today is limited, I turned it into an example. The example can use some improvements too.
Thank you, tbscope, for spending so much time to write wiki articles! Just two small notes for further improvements: Creating a QTextDocument in each paint event is too heave. Better store a private pointer. Further, there is no need to create a pixmap and paint it, you can directly use the painter: QTextDocument::drawContents().
I just remember, that wysota also have a rich text button in his wwWidgets: http://www.wysota.eu.org/wwwidgets/d...extbutton.html.
Bookmarks