Python Forum
How to work with pointers in PyQt?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to work with pointers in PyQt?
#1
The Qt- framework was originally created for C++ and therefore contains pointers (both in the form of method parameters and in the form of return values). But there are no pointers in Python, so it is not clear how to write code using the PyQt library.

For example, in C++ I got the icon:
Information = QIcon(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation));

And in Python I try to do so:
from PyQt5.QtGui import QIcon
from PyQt5.Qtwidgets import QApplication, Qstyle
Information = QIcon(QApplication.style().standardIcon(QStyle.SP_MessageBoxInformation))
, but I get an error (just in the place where in C++ I turned to the pointer method!):
Error:
Information = QtGui.QIcon (QApplication.style.)(standardIcon(qstyle.SP_MessageBox Information)) AttributeError:' NoneType ' object does not have 'standard' icon attribute
Probably there is some General rule of working with pointers, by which the PyQt library was created. How to work with them?
Reply
#2
In Linux I use

Information = QIcon.fromTheme("info")
Reply
#3
(Feb-06-2019, 02:18 PM)Axel_Erfurt Wrote: In Linux I use

Information = QIcon.fromTheme("info")

Thank you, the icon is created and has not an empty value, but for some reason is not displayed in the dialog. Maybe because I have Kubuntu.
I found another way:
IconsOfMessages = {}
IconsOfMessages['Information'] = QtWidgets.QApplication.instance().style().standardIcon(QStyle.SP_MessageBoxInformation)
IconsOfMessages['Warning'] = QtWidgets.QApplication.instance().style().standardIcon(QStyle.SP_MessageBoxWarning)
IconsOfMessages['Critical'] = QtWidgets.QApplication.instance().style().standardIcon(QStyle.SP_MessageBoxCritical)
Reply
#4
There are specific Message Windows you can use, they automatically have the right symbol

QMessageBox.information
QMessageBox.warning
QMessageBox.critical

for example

    def about(self):
        QMessageBox.information(self, "About myApp",
                "<center><b>myApplication</b><br>1.0<br>"
                "© 2019</center>")
Reply
#5
(Feb-06-2019, 04:25 PM)Axel_Erfurt Wrote: There are specific Message Windows you can use, they automatically have the right symbol

QMessageBox.information
QMessageBox.warning
QMessageBox.critical

for example

    def about(self):
        QMessageBox.information(self, "About myApp",
                "<center><b>myApplication</b><br>1.0<br>"
                "© 2019</center>")

Thank you, but I have a long processing that should work in the background. Therefore, the dialog boxes are not suitable, I chose to display messages about the current process on the text field of the form.
But at the end of the work I show the final result with the help of the dialog boxes you have proposed :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Turtle. Pointers of the "arrow" direction of the vector. roomONmoon 1 675 Dec-09-2023, 11:49 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020