I need a QPushButton with two colors in the text. I found a solution with a html code in QTextDocument and it\'s working. But I need center align and the html code isn\'t wo
There is a bug report about this. When you use QTextDocument::drawContents, it tends to ignore the aligments. To make it work, set the text width using QTextDocument::setTextWidth.
QTextDocument doc;
doc.setHtml("Button
1
");
doc.setTextWidth(doc.size().width());
QPixmap pixmap(doc.size().width(), doc.size().height());
pixmap.fill( Qt::transparent );
QPainter painter(&pixmap);
doc.drawContents(&painter);
QPushButton button;
button.setIconSize(pixmap.size());
button.setIcon(pixmap);
button.show();