Skip to content

Qt for Python

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

3.4k Topics 15.0k Posts
Qt 6.11 is out! See what's new in the release blog
  • looking for a code editor widget for Qt for Python

    Unsolved
    12
    1 Votes
    12 Posts
    4k Views
    RokeJulianLockhartR
    Indeed; the effort is possible to subscribe to, at invent.kde.org/teams/goals/streamlined-application-development-experience/-/work_items/9.
  • Creating Python bindings for KSyntaxHighlighter with shiboken

    Unsolved
    3
    0 Votes
    3 Posts
    690 Views
    M
    see also: looking for a code editor widget for Qt for Python
  • Possible mistake in the translation example?

    Unsolved
    5
    1 Votes
    5 Posts
    334 Views
    SGaistS
    @friedemannkleint said in Possible mistake in the translation example?: https://codereview.qt-project.org/c/pyside/pyside-setup/+/770427 ? Nice ! Thanks
  • pyside6-lupdate does not extract translations from Python files when given a directory

    Unsolved
    2
    0 Votes
    2 Posts
    163 Views
    Nils SjobergN
    You need to pass all the .py files in the directory to pyside6-lupdate, or use pyside6-project lupdate.
  • 0 Votes
    13 Posts
    702 Views
    J
    @JonB OK, for future readers here's the code I ended up with. It's a lot simpler than all the hallucinations provided by Google. I'm pretty sure it's not the canonical way to do this but it works and I'll continue studying the links provided in this thread. import sys from PySide6.QtCore import QFile from PySide6.QtWidgets import QApplication, QVBoxLayout, QWidget from PySide6.QtUiTools import QUiLoader def load_ui(ui_file_path: str) -> QWidget: loader = QUiLoader() ui_file = QFile(ui_file_path) if not ui_file.open(QFile.ReadOnly): print("Cannot open ui file") sys.exit(-1) ui = loader.load(ui_file) ui_file.close() return ui class MainWindow(QWidget): def __init__(self, ui:QWidget): super().__init__() self.ui = ui self.setWindowTitle("My Qt Designer App") layout = QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(ui) # Load comboBox items #ui.comboBox.addItems(getLoginCandidates(dbEngine)) ui.pushButton.clicked.connect(self.on_submit_clicked) def on_submit_clicked(self): print("The button was clicked!") if __name__ == "__main__": app = QApplication(sys.argv) ui = load_ui("../ui/test.ui") window = MainWindow(ui) window.show() rc = app.exec() sys.exit(rc)
  • Detecting checkbox toggle via keyboard on a QTreeWidgetItem

    Solved
    2
    0 Votes
    2 Posts
    140 Views
    Christian EhrlicherC
    You should get a https://doc.qt.io/qt-6/qtreewidget.html#itemChanged signal when the data of an item changes.
  • 0 Votes
    4 Posts
    299 Views
    JKSHJ
    @FatesealMagic said in How do I make my QMainWindow's contents dynamically resize after floating a QDockWidget?: I tried this code on a different machine with Ot/PySide6 6.11.0 and it worked as expected. Thank you! EDIT: For completeness, apparently this issue only impacts very specific QT versions: https://stackoverflow.com/questions/79999518/how-do-i-make-my-qmainwindows-contents-dynamically-resize-after-floating-a-qdoc/79999535#79999535 Indeed: https://qt-project.atlassian.net/browse/QTBUG-147209
  • Do I need to add qmldir for python objects exposed as singleton instances?

    Unsolved
    6
    0 Votes
    6 Posts
    1k Views
    L
    hey helping you out if you've not figured it out yet since the previous poster was very vague, after some testing myself you do you need to use qmlRegisterSingletonInstance() function to regsiter an existing precreated instance from python to QML there is no decorator that does this for obvious reasons. Going for the decorator is only for regsitering it as usable property Type and/or be used by QML to create. To auto generate the qmltypes I suggest you use something like "pyside6-qml-stubgen" library I found this works best as it is able to run regsiter types even from the function if you make a seperate file that is run when imported. Then you need to add whatever folder the library generates to your QML import path for the linter to know of it if you're using something like VSCode qml extensions.
  • Pyside6 Slot with Name arg crashes app

    Unsolved
    4
    0 Votes
    4 Posts
    346 Views
    F
    That produces file:///../Example/Main.qml:11: TypeError: Property 'testMethod' of object Example/Controller is not a function - an instance of Controller is needed.
  • How to make QRangeModel in Python PySide6 with pure strings?

    Moved Unsolved
    6
    0 Votes
    6 Posts
    536 Views
    F
    Support for string tables has been added in 6.12.
  • QWidgets Pixmap not appearing

    Solved
    2
    0 Votes
    2 Posts
    232 Views
    SGaistS
    Hi, Your drawn widget is never shown. That said, please stop using globals for everything you are doing. Take the time to learn how to build proper widgets and use signals and slots cleanly. Take a look at the image viewer example for a start. There are many others.
  • aboutQt() Runtime Error

    Solved pyside python
    3
    0 Votes
    3 Posts
    298 Views
    S
    @JonB said in aboutQt() Runtime Error: I thought you were just supposed to write something like: QtWidgets.QMessageBox.aboutQt(None) This works perfectly, thank you
  • PySide6 6.11.1: qtquickshapesdesignhelpersplugin.dll not found

    Solved
    12
    0 Votes
    12 Posts
    868 Views
    F
    Solved in PySide 6.11.2
  • Cannot set QDialog modal

    Unsolved
    4
    0 Votes
    4 Posts
    367 Views
    JonBJ
    @oldbrad So far as I recall, you should have no trouble having a modal dialog on top of all/any other windows in an application, certainly under Xorg if maybe not under Wayland, and without setting Always on Top. But I think your choice of self.setWindowModality(Qt.WindowModal) is wrong, that is looking for one parent to be modal to and you are not passing any. As per https://doc.qt.io/qt-6/qt.html#WindowModality-enum you should use Qt::ApplicationModal if you are not going to set a parent window for it to be modal against.
  • 0 Votes
    5 Posts
    463 Views
    SGaistS
    @PyXiion Sure thing Here is the link: https://qt-project.atlassian.net/browse/PYSIDE-3409
  • 0 Votes
    10 Posts
    1k Views
    1
    New issue created: https://qt-project.atlassian.net/browse/PYSIDE-3405
  • Loading multiple .ui files

    Solved pyside python
    3
    0 Votes
    3 Posts
    380 Views
    S
    @JonB said in Loading multiple .ui files: On a side note: as per another newcomer's question in another topic, I think you should re-examine your use of .ui file dynamic loading. Before you get into the habit of using it you would be much better off changing over to the uic method. See @friedemannkleint reply to a related situation at https://forum.qt.io/post/839262 and my reply. You/nearly everybody should be using Option A: Generating a Python class where you are currently using Option B: Loading it directly. What exactly makes Option A better than Option B?
  • Using QUiLoader to load a composite widget

    Unsolved
    3
    0 Votes
    3 Posts
    365 Views
    JonBJ
    @HenryInUtah At least from C++ unless it is any different from Python/PySide: when you load a .ui file at runtime you get all its widgets but you do not get "variables" for each one, like you do when you generate code from it via uic. That means you have to "find" widgets to address them, via QWidget.findChild/findChildren() from a top-level widget. You would have to do that to read/write their values or attach signals, etc. Is that not the situation you are in? Which is pretty inconvenient, and one of the many reasons why most of us do not pick dynamic runtime loading of the .ui file but instead use uic to generate "variables" for each widget we can use directly, as @friedemannkleint has recommended.
  • TypeError: unbound method QFileDialog.selectedFiles() needs an argument

    Solved pyside python
    6
    0 Votes
    6 Posts
    534 Views
    S
    @JonB said in TypeError: unbound method QFileDialog.selectedFiles() needs an argument: [Btw your Image files string clearly looks wrong --- count the parentheses --- so that may be interfering with its filter behaviour.] Ah, I somehow missed that before. Yep, adding the extra ) fixed it. @JonB said in TypeError: unbound method QFileDialog.selectedFiles() needs an argument: I just noticed that even if you do want multiple files selected there is actually a static function for that too: This works perfectly and does exactly what I was trying to do, thank you
  • 0 Votes
    4 Posts
    920 Views
    jsulmJ
    @demotu Take a look at https://forum.qt.io/topic/164253/about-accessing-the-bug-report-system?_=1784033640203