setting QMessage IconPixmap to the PyQt built-in icons
-
wrote on 25 Oct 2024, 05:12 last edited by explorer100
Hello.
In trying to set the icon of the QMessage dialog to one of the PyQt6 builtin icons using:
apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
apply_icon = self.style().standardIcon(apply_pixmap)I get,
TypeError: setIcon(self, a0: QMessageBox.Icon): argument 1 has unexpected type 'QIcon'Trying the setIconPixmap using:
apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
self.message.setIconPixmap(apply_pixmap)I get,
TypeError: setIconPixmap(self, a0: QPixmap): argument 1 has unexpected type 'StandardPixmap'Any suggestion to address this?
-
Hello.
In trying to set the icon of the QMessage dialog to one of the PyQt6 builtin icons using:
apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
apply_icon = self.style().standardIcon(apply_pixmap)I get,
TypeError: setIcon(self, a0: QMessageBox.Icon): argument 1 has unexpected type 'QIcon'Trying the setIconPixmap using:
apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
self.message.setIconPixmap(apply_pixmap)I get,
TypeError: setIconPixmap(self, a0: QPixmap): argument 1 has unexpected type 'StandardPixmap'Any suggestion to address this?
@explorer100 setIcon does not accept a QIcon, please read documentation: https://doc.qt.io/qt-6/qmessagebox.html#icon-prop
https://doc.qt.io/qt-6/qmessagebox.html#iconPixmap-prop accepts QPixmap as you can see in documentation (https://doc.qt.io/qt-6/qmessagebox.html#iconPixmap-prop). You are passing a StandardPixmap. Create a QPixmap and pass it to setIconPixmap.
-
-
wrote on 26 Oct 2024, 04:33 last edited by
@jsulm said in setting QMessage IconPixmap to the PyQt built-in icons:
QPixmap
thank you, but if I am interested in one of the built-in icons provided by PyQt, is there a way to convert them to QPixmap?
-
Hi,
You have to do it in two steps:
- get the standard icon using QStyle::standardIcon
- get the pixmap from the icon using one of the QIcon::pixmap overload
-
wrote on 26 Oct 2024, 16:40 last edited by
Thank you .. this worked really well:
apply_pixmap = getattr(QStyle.StandardPixmap, "SP_DialogApplyButton") apply_icon = self.style().standardIcon(apply_pixmap) q_pixmap = apply_icon.pixmap(apply_pixmap) self.message.setIconPixmap(q_pixmap)
-
Out of curiosity, why are you using getattr ?
-
wrote on 27 Oct 2024, 03:53 last edited by
@SGaist said in setting QMessage IconPixmap to the PyQt built-in icons:
Out of curiosity, why are you using getattr ?
I have no specific reason to use getattr...
My objective is just to show this built-in icon in QMessage.
Is there a more straightforward way of doing it? -
@SGaist said in setting QMessage IconPixmap to the PyQt built-in icons:
Out of curiosity, why are you using getattr ?
I have no specific reason to use getattr...
My objective is just to show this built-in icon in QMessage.
Is there a more straightforward way of doing it?wrote on 27 Oct 2024, 08:41 last edited by JonB@explorer100 said in setting QMessage IconPixmap to the PyQt built-in icons:
getattr(QStyle.StandardPixmap, "SP_DialogApplyButton")
Is there a more straightforward way of doing it?QStyle.StandardPixmap.SP_DialogApplyButton
(PySide6/PyQt6) should work for this. (Or probablyQStyle.SP_DialogApplyButton
if PySide2/PyQt5.) -
wrote on 27 Oct 2024, 12:39 last edited by explorer100
Thank you.. that worked for PyQt6
QStyle.StandardPixmap.SP_DialogApplyButton
-
Hi,
You have to do it in two steps:
- get the standard icon using QStyle::standardIcon
- get the pixmap from the icon using one of the QIcon::pixmap overload
wrote on 27 Oct 2024, 16:43 last edited byJust to complete the discussion, is there a simpler way to do this than:
apply_pixmap = QStyle.StandardPixmap.SP_DialogApplyButton
apply_icon = self.style().standardIcon(apply_pixmap)
q_pixmap = apply_icon.pixmap(apply_pixmap)Thank you all for the advice.
-
apply_icon = self.style().standardIcon(QStyle.StandardPixmap.SP_DialogApplyButton) q_pixmap = apply_icon.pixmap(QStyle.StandardPixmap.SP_DialogApplyButton)
-
apply_icon = self.style().standardIcon(QStyle.StandardPixmap.SP_DialogApplyButton) q_pixmap = apply_icon.pixmap(QStyle.StandardPixmap.SP_DialogApplyButton)
wrote on 28 Oct 2024, 06:09 last edited by explorer100That won't work because you don't have apply_pixmap anymore to use.
I think you meat this:
apply_icon = self.style().standardIcon(QStyle.StandardPixmap.SP_DialogApplyButton)
q_pixmap = apply_icon.pixmap(QStyle.StandardPixmap.SP_DialogApplyButton) -
That won't work because you don't have apply_pixmap anymore to use.
I think you meat this:
apply_icon = self.style().standardIcon(QStyle.StandardPixmap.SP_DialogApplyButton)
q_pixmap = apply_icon.pixmap(QStyle.StandardPixmap.SP_DialogApplyButton)@explorer100 Indeed, and fixed.
1/13