Well in the end I was able to solve that<br><br>just in case anyone needs it:<br><br>def sizeHint(self):<br> richTextLabel = QtGui.QTextDocument()<br> richTextLabel.setHtml(self._htmlText)<br> sizeHint = QtCore.QSize(richTextLabel.size().width()<br>
+ 2*RPushButton.SIZEADJ,<br> richTextLabel.size().height()<br> + 2*RPushButton.SIZEADJ)<br> if not self.icon().isNull():<br>
sizeHint = QtCore.QSize(sizeHint.width()<br> + self.iconSize().width()<br> + 3*RPushButton.SIZEADJ,<br> max(sizeHint.height()<br>
+ 2*RPushButton.SIZEADJ,<br> self.iconSize().height()<br> + 2*RPushButton.SIZEADJ))<br> return sizeHint<br>
<br> ## Reimplementation of paintEvent<br> #<br> # See <a href="http://doc.trolltech.com/latest/qwidget.html#paintEvent">http://doc.trolltech.com/latest/qwidget.html#paintEvent</a><br> def paintEvent(self, event):<br>
<br> p = QtGui.QStylePainter(self)<br> buttonRect = QtCore.QRect(self.rect())<br><br> richTextLabel = QtGui.QTextDocument()<br> richTextLabel.setHtml(self._htmlText)<br><br> richTextPixmap = QtGui.QPixmap(richTextLabel.size().width(),<br>
richTextLabel.size().height())<br> richTextPixmap.fill(QtCore.Qt.transparent)<br> richTextPainter = QtGui.QPainter(richTextPixmap)<br> richTextLabel.drawContents(richTextPainter,<br>
QtCore.QRectF(richTextPixmap.rect()))<br><br> richTextPainter.end()<br> <br> if not self.icon().isNull():<br> point = QtCore.QPoint(buttonRect.x() +<br> self.iconSize().width() + RPushButton.SIZEADJ,<br>
buttonRect.y() + buttonRect.height() / 2)<br> else:<br> point = QtCore.QPoint(buttonRect.x(),<br> buttonRect.y() + buttonRect.height() / 2)<br><br> buttonRect.translate(point.x() +<br>
RPushButton.SIZEADJ,<br> point.y() - richTextPixmap.height() / 2)<br><br> p.drawControl(QtGui.QStyle.CE_PushButtonBevel, self.getStyleOption())<br> <br>
p.drawPixmap(buttonRect.left(), buttonRect.top(),<br> richTextPixmap.width(), richTextPixmap.height(),<br> richTextPixmap)<br> if not self.icon().isNull():<br> p.drawPixmap(RPushButton.SIZEADJ, RPushButton.SIZEADJ,<br>
self.iconSize().width(), self.iconSize().height(),<br> self.icon().pixmap(self.iconSize()))<br><br><div class="gmail_quote">On 31 January 2011 13:18, Fernando Cosso <span dir="ltr"><<a href="mailto:ferdemza@gmail.com">ferdemza@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi all<br><br>I am having new issues with that Rich Text Push Button and I tried everything but so far I have not succeed.<br>
<br>I wan my push button to have the icon and the text aligned left. I know how to change the text position since is in the reimplementation of the paintEvent. I just change that little bit.<br>
I should also change the sizeHint but I will come to that latter.<br><br>The thing is that I don't know how to align the icon. I know I should change something related to this line:<br>p.drawControl(QtGui.QStyle.CE_PushButton, self.getStyleOption())<br>
<br>but I don't know what. I've read the Qt documentation but I am more confused that before.<br><br>Any help, hint, whatever would be much appreciated!<br><br>Best Regards<br><br> def paintEvent(self, event):<br>
<br> p = QtGui.QStylePainter(self)<br> buttonRect = QtCore.QRect(self.rect())<br><br> richTextLabel = QtGui.QTextDocument()<br>
richTextLabel.setHtml(self._htmlText)<br><br> richTextPixmap = QtGui.QPixmap(richTextLabel.size().width(),<br> richTextLabel.size().height())<br> richTextPixmap.fill(QtCore.Qt.transparent)<br>
richTextPainter = QtGui.QPainter(richTextPixmap)<br> richTextLabel.drawContents(richTextPainter,<br> QtCore.QRectF(richTextPixmap.rect()))<br><br> richTextPainter.end()<br>
<br> if not self.icon().isNull():<br> point = QtCore.QPoint(buttonRect.x() +<br> self.iconSize().width() + RPushButton.SIZEADJ,<br> buttonRect.y() + buttonRect.height() / 2);<br>
else:<br> point = QtCore.QPoint(buttonRect.x(),<br> buttonRect.y() + buttonRect.height() / 2);<br><br> buttonRect.translate(point.x() +<br> RPushButton.SIZEADJ,<br>
point.y() - richTextPixmap.height() / 2);<br><br> p.drawControl(QtGui.QStyle.CE_PushButton, self.getStyleOption())<br> p.drawPixmap(buttonRect.left(), buttonRect.top(),<br> richTextPixmap.width(), richTextPixmap.height(),<br>
richTextPixmap);<br>
</blockquote></div><br>