Skip to content

Qt for Python

For discussion and questions about Qt for Python (PySide & Shiboken)

3.3k Topics 14.6k Posts
  • Refresh data in view

    Solved
    9
    0 Votes
    9 Posts
    1k Views
    N
    Thanks for your help guys i have solved the issue :).
  • 0 Votes
    6 Posts
    890 Views
    JonBJ
    @MrAWD Using PyCharm as the IDE results in the same behaviour: although the program runs fine the editor claims Qt.LeftButton is an "unresolved attribute reference" and you cannot "follow" it to find any further information. At Qt6 PySide6 enum Flags were moved from all appearing in the "global" Qt class and being implemented in Shiboken to being true Python enums in a specific class like Qt.MouseButton. You are supposed to change over your existing code to use the new definitions. However Doing a Smooth Transition from the Old Enums explains Changing all the enum code to suddenly use the new syntax is cumbersome and error-prone, because such necessary changes are not easy to find. Therefore a forgiveness mode was developed: The forgiveness mode allows you to continue using the old constructs but translates them silently into the new ones. If you for example write [...] you get in reality a construct that mimics the following code which is the recommended way of writing Flags and Enums: [...] This has the effect that you can initially ignore the difference between old and new enums, as long as the new enums are properties of classes. See also https://doc.qt.io/qtforpython-6/considerations.html#enums-behavior-in-pyside and https://doc.qt.io/qtforpython-6/developer/enumfeatures_doc.html#the-set-of-enum-features. I have not looked into it further, but whatever that forgiveness mode does it must be enough to make the code work correctly when run but must create the definition or whatever "dynamically at runtime" such that IDEs like PyCharm or your Eclipse do not evaluate it, know nothing about it and hence complain it is "undefined". Note that this is a PySide6 feature only: if try the code under PyQt6 I get the AttributeError on Qt.RightButton. To help you spot all the changed definitions and upgrade you could either (a) use the links above to tell PySide6 not to do the forgiveness mode and hence error at runtime like PyQt6 does or (b) in the solution at Migrating to Qt6/PyQt6: what are all the deprecated short-form names in Qt5? someone has written a script: I wrote a script to extract all the short-form and corresponding fully qualified enum names from the PyQt6 installation. It then does the conversions automatically: Similarly there is PyQtEnumConverter 1.0. Although these are PyQt-specific you might either adapt them or take inspiration from their code to achieve similar for PySide.
  • 0 Votes
    1 Posts
    190 Views
    No one has replied
  • 0 Votes
    2 Posts
    343 Views
    JonBJ
    @markleo https://qfluentwidgets.com/pages/designer/ I cannot imagine that Qt Designer would document, explain or tutorial on that third-party app, it would be up to the third-party to do so, as per the link.
  • popup progress dialog

    Unsolved
    3
    0 Votes
    3 Posts
    335 Views
    E
    That worked great!! thank you very much.
  • How to configure the PyCharm external tool of `Qt Designer`?

    Solved qt for python python
    5
    0 Votes
    5 Posts
    2k Views
    M
    I fond it by : % find /opt/anaconda3/ -name "Designer.app" /opt/anaconda3//pkgs/qt6-main-6.7.3-h2fbab7f_1/lib/qt6/bin/Designer.app
  • 0 Votes
    7 Posts
    709 Views
    SGaistS
    Sorry, I just tested it on macOS (I don't have a Win10 machine at hand), and it's working properly. Can you test your application using the fusion style ?
  • Can Qt Creator create PyQt project?

    Solved python qt for python
    3
    0 Votes
    3 Posts
    602 Views
    JonBJ
    @markleo As @Pl45m4 has said. PyQt and PySide are so similar that there is no reason why you should not create a PySide project and then just substitute PyQt for PySide everywhere it occurs. Plus project templates are really only a couple of files and lines of code, once you've seen one you are not missing out if you just write/copy in the few lines.
  • 0 Votes
    2 Posts
    234 Views
    jsulmJ
    @markleo said in For large Qt desktop projects, how is the database generally used in combination?: Since large databases such as MySQL and PostgreSQL need to be installed on a PC Those are typically installed on a server and clients access that server. It would be unusual to install such SQL servers on users machines. Whether SQLite is sufficient or not really depends on your needs. It is, for example, not designed to be accessed in parallel by several applications at the same time. So, what are your requirements? Are your clients going to access same databases? If so, you should consider client/server architecture using MySQL/PostgreSQL.
  • 1 Votes
    2 Posts
    524 Views
    Pl45m4P
    @markleo said in Is there any PyQt demos examples of architecture for modular design of large projects?: Does PyQt have similar sample schemes that can be borrowed? These are the official PySide Qt examples https://doc.qt.io/qtforpython-6/examples/index.html and here are some PyQt GitHub examples: https://github.com/pyqt/examples
  • Issue with padding/placement PyQT6 Python

    Unsolved
    4
    0 Votes
    4 Posts
    1k Views
    SGaistS
    Something like the following ? # code block import sys from PyQt6.QtWidgets import ( QApplication, QMainWindow, QWidget, QVBoxLayout, QPushButton, QStackedWidget, QLabel, QHBoxLayout, QGridLayout ) from PyQt6.QtCore import Qt from PyQt6.QtGui import QIcon, QFont, QFontDatabase class MainWindow(QMainWindow): def __init__(self): super().__init__() # Application Configuration self.resize(800, 600) self.setWindowIcon(QIcon("./Images/clown.ico")) self.setWindowTitle("Recalcitrant V1.0.0") # Create a central widget and main layout self.centralWidget = QWidget() self.setCentralWidget(self.centralWidget) mainLayout = QHBoxLayout(self.centralWidget) # Use QHBoxLayout for side-by-side self.sidebarFrame = self.createSidebarFrame() self.stacked_widget = QStackedWidget() # Create frames self.dashboardFrame = self.createDashboardFrame() self.frame2 = self.create_frame("This is Frame 2") self.frame3 = self.create_frame("This is Frame 3") # Add frames to the stacked widget self.stacked_widget.addWidget(self.dashboardFrame) self.stacked_widget.addWidget(self.frame2) self.stacked_widget.addWidget(self.frame3) # Add sidebar and stacked widget to the main layout mainLayout.addWidget(self.sidebarFrame) # Add sidebar first mainLayout.addWidget(self.stacked_widget) # Then the stacked widget mainLayout.setContentsMargins(0, 0, 0, 0) mainLayout.setSpacing(0) # Set the fixed width for the sidebar self.sidebarFrame.setFixedWidth(150) def createSidebarFrame(self): sidebarWidget = QWidget() sidebarWidget.setObjectName("sidebar") sidebar = QVBoxLayout() sidebar.setAlignment(Qt.AlignmentFlag.AlignTop) # Align sidebar to the top sidebarWidget.setStyleSheet(""" QWidget#sidebar { background-color: #22222E; border-radius: 10px; } QPushButton#button { background-color: #22222E; border: 2px solid #ffffff; border-radius: 10px; padding: 5px; } QPushButton#button:hover { background-color: #393A5A; } QLabel#sidebarLabels { text-align: center; color: white; } """) sidebarWidget.setLayout(sidebar) # Dashboard self.modulesText = QLabel("<div style='text-align: center;'>test</div>") self.modulesText.setObjectName("sidebarLabels") sidebar.addWidget(self.modulesText) self.test = QPushButton("DASHBOARD") self.test.setMaximumWidth(150) self.test.setMinimumWidth(100) self.test.setObjectName("button") self.test.clicked.connect(lambda: self.switch_frame("dashboard")) sidebar.addWidget(self.test) # test self.test = QLabel("<div style='text-align: center;'>test</div>") self.test.setObjectName("sidebarLabels") sidebar.addWidget(self.test) self.test = QPushButton("test") self.test.setMaximumWidth(150) self.test.setMinimumWidth(100) self.test.setObjectName("button") self.test.clicked.connect(lambda: self.switch_frame(1)) sidebar.addWidget(self.test) # test self.test = QLabel("<div style='text-align: center;'>test</div>") self.test.setObjectName("sidebarLabels") sidebar.addWidget(self.test) self.test = QPushButton("test") self.test.setMaximumWidth(150) self.test.setMinimumWidth(100) self.test.setObjectName("button") self.test.clicked.connect(lambda: self.switch_frame(2)) sidebar.addWidget(self.test) sidebar.setContentsMargins(0, 5, 0, 5) #sidebar.setSpacing(0) sidebarWidget.setContentsMargins(0, 5, 0, 5) return sidebarWidget # Return the sidebar widget, not the layout def createDashboardFrame(self): frame = QWidget() frame.setStyleSheet(""" QLabel#label { border: 2px solid #ffffff; border-radius: 10px; padding: 0px; } """) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) frame.setLayout(layout) hbox = QHBoxLayout() layout.addLayout(hbox) test = QLabel("<div style='text-align: center;'>test test</div>") test.setObjectName("label") hbox.addWidget(test) test = QLabel("<div style='text-align: center;'>test test</div>") test.setObjectName("label") hbox.addWidget(test) test = QLabel("<div style='text-align: center;'>test test test</div>") test.setObjectName("label") hbox.addWidget(test) vbox = QVBoxLayout() layout.addLayout(vbox) button = QPushButton("test") vbox.addWidget(button) button = QPushButton("test") vbox.addWidget(button) button = QPushButton("test") vbox.addWidget(button) return frame def create_frame(self, text): """Helper function to create a frame with a label.""" frame = QWidget() layout = QVBoxLayout() label = QLabel(text) layout.addWidget(label) frame.setLayout(layout) return frame def switch_frame(self, index): """Switch to the specified frame.""" if index == "dashboard": self.stacked_widget.setCurrentIndex(0) self.test.setStyleSheet("background-color: #393A5A;") self.test.setStyleSheet("") self.test.setStyleSheet("") elif index == 1: self.stacked_widget.setCurrentIndex(index) self.test.setStyleSheet("") self.test.setStyleSheet("background-color: #393A5A;") self.test.setStyleSheet("") elif index == 2: self.stacked_widget.setCurrentIndex(index) self.test.setStyleSheet("") self.test.setStyleSheet("") self.test.setStyleSheet("background-color: #393A5A;") if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec())
  • Newbie question - connect to label PyQt

    Moved Solved
    8
    0 Votes
    8 Posts
    879 Views
    E
    Thank you @Axel-Spoerl and @JonB , works great and I understood all including lambda. Great help
  • Hi, how to use Qt Designer on macOS?

    Solved qt for python
    4
    0 Votes
    4 Posts
    2k Views
    jsulmJ
    @markleo said in Hi, how to use Qt Designer on macOS?: I don't find a button called "Design" Please look again: it is right there on the left side. It is greyed out because you do not have an ui file yet.
  • Weird grey backgrounds and other issues when I recreated my virtual environment

    Unsolved
    7
    0 Votes
    7 Posts
    635 Views
    SGaistS
    You're likely on Windows 11 and the new windows11 style has some issues.
  • Visual Studio 2022 17.11 compilation issues when trying to build Pyside6

    Unsolved
    1
    0 Votes
    1 Posts
    169 Views
    No one has replied
  • Draw lines,arcs at design time then change color on an event at runtime

    Unsolved
    11
    0 Votes
    11 Posts
    1k Views
    JonBJ
    @JimLomax said in Draw lines,arcs at design time then change color on an event at runtime: There is no QGraphicsArcItem, the ellipse item can be told to create partial ellipses but I haven't found a way to make it create arcs - it creates pie pieces. 2. Using the QGraphicsPathItem sort of works but I haven't found a way to stop it adding a line to the start of the arc I don't have anything to say about QML vs widgets as I only use the latter. But if you are still interested in how to draw an arc on a QGraphicsScene without the pie/line QT QGraphicsScene Drawing Arc shows how to do that.
  • 0 Votes
    4 Posts
    331 Views
    SGaistS
    You're welcome ! Since this is what you wanted, please mark the thread as solved using the "Topic Tool" button or the three dotted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)
  • Divide the MainWindow class into smalller classes

    Unsolved
    8
    0 Votes
    8 Posts
    756 Views
    A
    Making everything into custom widgets would be more work that sticking with that big class, but I'll definitely keep this in mind. Thank you both @jsulm and @JonB for help.
  • Setting setItemAlignment breaks setSelectionMode in QListWidget

    Unsolved
    2
    0 Votes
    2 Posts
    224 Views
    SGaistS
    Hi, It seems you have indeed found something. It's reproducible as well in C++. You should open a ticket on the bug tracker with you reproducer (don't forget to check if something similar has already been reported).
  • 0 Votes
    3 Posts
    440 Views
    B
    Hi and thanks for your welcome. Good question, I'm trying to create Qt bindings for Ada language. Some attempts with C++ were failing due to some C++ subtleties. But Python provides C API which I can used easily with Ada. I provide some very first Qt bindings for Ada. But class inheritance is still in Python. I wanted to make them full Ada. I'm able to instantiate a class inherited from QRasterWindow (for instance) but a call to the method metric (for instance) provoques a seg fault. (for simplicity I post the code in C)