HTML inside QPushButton - how to insert images?
-
Hi all,
I want to create Buttons similar to the ones here:
!http://i42.tinypic.com/s64nqw.png(Copy Dialog)!I have found that the following code be used to format text in QPushButton - but I am not able to insert images into HTML code.
@QPushButton *button = new QPushButton();
QTextDocument Text;Text.setHtml("<h2><font color=white><font face=\"Segoe UI\">Close This App</font></h2>" "<p>More Text</p>"); QPixmap pixmap(Text.size().width(), Text.size().height()); pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); Text.drawContents(&painter, pixmap.rect()); QIcon ButtonIcon(pixmap); button->setIcon(ButtonIcon); button->setIconSize(pixmap.rect().size());@
Could someone please help? TIA!
Cheers
Dee -
Try to create widget with your images, text and others and do that:
@void yourWidget::paintEvent(QPaintEvent*)
{
QStylePainter painter(this);
QStyleOptionButton option;option.initFrom(this);
painter.drawControl(QStyle::CE_PushButton, option);
}@
I am not sure but it must work -
[[Doc:QCommandLinkButton]]s provides a look like that you want. The descriptive text is a plaintext and cannot take HTML/images, though.
-
Got it.Thanks.