Skip to content

Qt for Python

For discussion and questions about Qt for Python (PySide 2)

3.1k Topics 13.6k Posts
  • QToolBox seamless tab title and content

    Unsolved
    1
    0 Votes
    1 Posts
    22 Views
    No one has replied
  • How to get the font name as readable text

    Unsolved
    6
    0 Votes
    6 Posts
    79 Views
    E

    @JonB : Thank you.
    Great tips, all works and I learned a lot. Super, will use your info.

  • Pyside6 on embedded linux

    Unsolved
    1
    0 Votes
    1 Posts
    18 Views
    No one has replied
  • 0 Votes
    2 Posts
    18 Views
    JonBJ

    No, you have to create that manually.

  • one model, two proxies, two views - Argg!

    Solved
    3
    0 Votes
    3 Posts
    147 Views
    R

    Thank you, this helped a lot. Your example works. I discovered a problem when I added in a second proxy model, but I will post that in a second topic.

  • slots and signals question with embedded widgets.

    Unsolved
    4
    0 Votes
    4 Posts
    64 Views
    SGaistS

    Hi,

    Don't ! Even if you think it's a silly error, you're not alone having fallen for that and your post might help somebody else in their investigation :-)

  • Refresh data in view

    Solved
    9
    0 Votes
    9 Posts
    142 Views
    N

    Thanks for your help guys i have solved the issue :).

  • 0 Votes
    6 Posts
    77 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
    25 Views
    No one has replied
  • 0 Votes
    2 Posts
    38 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
    57 Views
    E

    That worked great!! thank you very much.

  • 0 Votes
    5 Posts
    76 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
    172 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
    3
    0 Votes
    3 Posts
    64 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
    58 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
    41 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
    96 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
    154 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
    4
    0 Votes
    4 Posts
    84 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.

  • 0 Votes
    7 Posts
    167 Views
    SGaistS

    You're likely on Windows 11 and the new windows11 style has some issues.