[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] Custom Control again
From: Fernando Cosso <ferdemza () gmail ! com>
Date: 2011-01-31 18:18:24
Message-ID: AANLkTi=XfKF_2AM9Fi+4ND=CsAqFaM6zsSsS3rycBdt3 () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hi all
I am having new issues with that Rich Text Push Button and I tried
everything but so far I have not succeed.
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.
I should also change the sizeHint but I will come to that latter.
The thing is that I don't know how to align the icon. I know I should change
something related to this line:
p.drawControl(QtGui.QStyle.CE_PushButton, self.getStyleOption())
but I don't know what. I've read the Qt documentation but I am more confused
that before.
Any help, hint, whatever would be much appreciated!
Best Regards
def paintEvent(self, event):
p = QtGui.QStylePainter(self)
buttonRect = QtCore.QRect(self.rect())
richTextLabel = QtGui.QTextDocument()
richTextLabel.setHtml(self._htmlText)
richTextPixmap = QtGui.QPixmap(richTextLabel.size().width(),
richTextLabel.size().height())
richTextPixmap.fill(QtCore.Qt.transparent)
richTextPainter = QtGui.QPainter(richTextPixmap)
richTextLabel.drawContents(richTextPainter,
QtCore.QRectF(richTextPixmap.rect()))
richTextPainter.end()
if not self.icon().isNull():
point = QtCore.QPoint(buttonRect.x() +
self.iconSize().width() + RPushButton.SIZEADJ,
buttonRect.y() + buttonRect.height() / 2);
else:
point = QtCore.QPoint(buttonRect.x(),
buttonRect.y() + buttonRect.height() / 2);
buttonRect.translate(point.x() +
RPushButton.SIZEADJ,
point.y() - richTextPixmap.height() / 2);
p.drawControl(QtGui.QStyle.CE_PushButton, self.getStyleOption())
p.drawPixmap(buttonRect.left(), buttonRect.top(),
richTextPixmap.width(), richTextPixmap.height(),
richTextPixmap);
[Attachment #5 (text/html)]
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>
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic