Pixmap alignment in QPushButtons.
Raymond Osborn
rayosborn at mac.com
Sun Apr 26 16:58:47 BST 2020
Since PyQt 5.11, the MacOS version of PyQt5 appears to have had a number of issues, mostly to do with failing to repaint text boxes (e.g., see https://bugreports.qt.io/browse/QTBUG-68521 <https://bugreports.qt.io/browse/QTBUG-68521> and https://bugreports.qt.io/browse/QTBUG-68740 <https://bugreports.qt.io/browse/QTBUG-68740>). There were reports that this had been fixed by 5.12, but that has not been my experience. I haven’t had time to check on 5.14 yet. Everything seems to be fine on Linux, at least with 5.12.
I am writing to ask if anyone has also experienced an issue with the alignment of pixmaps in QPushButtons. I have subclassed QPushButton with the following code:
class NXColorButton(QtWidgets.QPushButton):
def __init__(self, parent=None):
super(NXColorButton, self).__init__(parent)
self.setFixedSize(20, 20)
self.setIconSize(QtCore.QSize(12, 12))
pixmap = QtGui.QPixmap(QtCore.QSize(12, 12))
pixmap.fill(QtGui.QColor(QtCore.Qt.white))
self.setIcon(QtGui.QIcon(pixmap))
In PyQt 5.9, this produced the following button on the right:
In PyQt 5.14.2, it produces this:
When I query the sizes, they agree with the values in the code, but although the pixel map is square, the QPushButton below it is clearly not 20x20. It’s rectangular for a start. I can make it nearly square if I increase the size to 30x30. For comparison, the QLineEdit box to the left is 21 pixels high.
I can write up a bug report but I wanted to find out if this is a known issue or easy to fix.
—
Ray Osborn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200426/7e63d887/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Color Button PyQt 5.9.7.png
Type: image/png
Size: 8428 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200426/7e63d887/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Color Button PyQt 5.14.2.png
Type: image/png
Size: 8350 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200426/7e63d887/attachment-0003.png>
More information about the PyQt
mailing list