Skip to content

Qt for Python

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

3.3k Topics 14.6k Posts
  • How to make the UI expand according to the size of the window?

    Moved Unsolved
    2
    0 Votes
    2 Posts
    238 Views
    Christian EhrlicherC
    @Azuna said in How to make the UI expand according to the size of the window?: setGeometry Use layouts instead hard-code the sizes.
  • How can I add a widget in a QTableWidget header?

    Unsolved qt for python python pyside
    2
    0 Votes
    2 Posts
    550 Views
    SGaistS
    Hi and welcome to devnet, I think this article is still valid.
  • Dialog Locations on Multiscreen app

    Unsolved pyside python
    6
    0 Votes
    6 Posts
    760 Views
    I
    @Improv-Jester Upgrading to 6.6.1 has fixed it! Thankyou for taking the time and for you sage advice.
  • Model/View Programming Guide: Python code in the Using model indexes section?

    Unsolved
    2
    0 Votes
    2 Posts
    216 Views
    JonBJ
    @PyRookie said in Model/View Programming Guide: Python code in the Using model indexes section?: The code snippets in the Using model indexes section of the Model/View Programming Guide don't match the textual description. As far as I am able to guess, they don't match the C++ version either. Sadly this does indeed seem to be true!
  • Qt3D no fragment shader code in Qt3DExtras materials

    Unsolved
    1
    0 Votes
    1 Posts
    158 Views
    No one has replied
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    16 Views
    No one has replied
  • No QImage.Format_RGB888 (PyQt6)

    Solved
    2
    0 Votes
    2 Posts
    746 Views
    JonBJ
    @AndrzejB Python Qt enums have moved at Qt6. Try QImage.Format.Format_RGB888. I don't think you will find documentation yet updated.
  • QML Button onClicked() - cannot open Dialog/PopUp until function finishes?

    Unsolved
    6
    0 Votes
    6 Posts
    1k Views
    jeremy_kJ
    @robliou said in QML Button onClicked() - cannot open Dialog/PopUp until function finishes?: @jeremy_k Hello Jeremy, thank you for taking the time to reply. So far, this sounds like the expected behavior. The Qt event loop is blocked as long as application code is running in the UI thread. OK, makes sense, but surely when i run progressBarDialog.open() this isn't blocking the GUI event loop, or is it? Isn't opening a dialog/ popup just a local event? I don't know what's meant by a local event. In my toy test on macOs, Dialog.open() followed by a long-running operation still shows the dialog before becoming unresponsive. I don't know that this is required by the interface. It's not inconceivable to me that some windowing systems might require a working event loop to show a window. toy.qml: import QtQuick.Window import QtQuick.Dialogs Window { visible: true MessageDialog { id: dialog } MouseArea { anchors.fill: parent onClicked: { console.log("pre"); dialog.open(); for (var i = 0; i < 500000000; i++) ; console.log("post"); } } } Secondly, the fact that I used QThread to run run_function should mean that a new thread is now running this function, so there should be no interference with the GUI event loop? It shouldn't interfere with the C++ event loop implementation. There will be contention for any python code run in an event handler, slot, etc. This is the interesting part. Is the Widgets implementation more or less free of python code? If so, this is the expected behavior. If not, or perhaps regardless, a comparison could be fruitful. I took another look at my QT Widgets code on how I achieved proper functioning. I'm lost in the description. If you can share a terse, brief example, that might help. If not, it sounds like you understand the Python and Qt widgets fundamentals. @robliou said in QML Button onClicked() - cannot open Dialog/PopUp until function finishes?: I suspect that QML, not Python, is causing the problem. The GUI locks when you try to both do something in the main GUI event loop (i.e. open a QML popup window) and also run a Python function, as triggered from a QML event (i.e. clicking a button). QML seems to automatically lock the main event loop, even if the Python function is called using a separate thread. Native code that is run from python (PySide and PyQt included) need to explicitly drop the global interpreter lock to allow other python threads to execute. It's possible that you've found a defect where this release is missing. The QML engine itself isn't likely to be involved. While a signal handler/QML event is running, that QML engine is blocking its thread's event loop. If you can put together a minimal example, that would help for a bug report. And as usual, try the latest release to verify that the issue hasn't already been addressed.
  • Set up Widgets in current tab lose layout and visibility?

    Unsolved
    12
    0 Votes
    12 Posts
    2k Views
    SGaistS
    @CAJJED said in Set up Widgets in current tab lose layout and visibility?: @SGaist thanks for the guidance, We engineers like big ugly monstrosity displays ;-) As an engineer, I have to vehemently disagree with that statement ;-) QListView + QStackedWidget Your QListView then drives the current widget shown from the QStackedWidget. Then you add as many QTabWidget you need to the QStackedWidget. This will be simpler and cleaner to manage.
  • This topic is deleted!

    Solved
    5
    0 Votes
    5 Posts
    37 Views
  • How to precisely modify screen colors by RGB channel?

    Moved Unsolved
    3
    0 Votes
    3 Posts
    314 Views
    K
    @Pl45m4 Ty for the reply! The "screen color" is just like a result. When I add a watermark of RGBA Image, the "screen color" would be changed. Just like this. [image: 32b221ab-2972-473f-af8c-b0b8224834db.png] You could find some red square there. The background color is #1E1F22, The red square is #211F22. The value of R channel increased 3. but when I use some lighter background like: [image: abb0bc92-cc7d-4f79-98e9-40f06a0e7d60.png] The background's color is #FFFFFF. The red square is #FFFAFA. The value of R channel is pure 255. In the algorithm, the watermark is added to one channel. Therefore, the DNN also accepts one channel data. but the way I add the watermark on the screen would change different channels in different condition. What I really want is, ideally, I can exactly change (reduce is better) one of the channel whatever the background color is. Or, regardless of small changes in other channels, the red channel's value should change whatever the background color is. (In the white background condition, the R channel is pure 255, whatever I added is 0 or 1)
  • This topic is deleted!

    Unsolved
    3
    0 Votes
    3 Posts
    25 Views
  • Visualization of Robot

    Unsolved
    2
    0 Votes
    2 Posts
    265 Views
    SGaistS
    Hi, It's a bit too vague a requirement. Based on what you wrote the first thing that comes to mind is: use QtMultimedia to show the video feed of the camera you have pointed to your robot. However, I don't think that it is the setup you currently have.
  • This topic is deleted!

    Unsolved
    3
    0 Votes
    3 Posts
    20 Views
  • How to use pyside6-lupdate?

    Solved
    9
    0 Votes
    9 Posts
    3k Views
    F
    A tutorial can be found at https://doc.qt.io/qtforpython-6/tutorials/basictutorial/translations.html .
  • This topic is deleted!

    Solved
    1
    0 Votes
    1 Posts
    6 Views
    No one has replied
  • Custom checkbox in a table column

    Unsolved
    14
    0 Votes
    14 Posts
    2k Views
    JonBJ
    @Gazi No, but createEditor() is called, which you could always save. There is editorEvent() too. I suggested you look at the Star Delegate code, which even has a void StarDelegate::commitAndCloseEditor() method. Did you do so?
  • QHeaderView doesn't have 'ResizeToContents' attribute

    Solved
    4
    0 Votes
    4 Posts
    2k Views
    JonBJ
    @Parthe Be aware: it's not just this one, it's (more or less) every Qt enum which has changed to be fully qualified at Qt6. In both PySide6 & PyQt6. And they have not changed the documentation, sadly. For this one I think you look at the doc page at https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QHeaderView.html#PySide6.QtWidgets.PySide6.QtWidgets.QHeaderView.ResizeMode. There you see: PySide6.QtWidgets.QHeaderView.ResizeMode QHeaderView will automatically resize.... QHeaderView.ResizeToContents I think you have to put these two together: so it actually needs to be ....QHeaderView.ResizeMode.ResizeToContents. And I guess for other enums similarly. Quite a while ago there was a guy who posted and had written some "conversion" program, or you could look at its source, for all the enum changes. But I can't recall where to find it.[*] See also https://doc.qt.io/qtforpython-6/considerations.html#the-differences-between-old-and-new-enums, e.g. Qt.AlignLeft becomes Qt.AlignmentFlag.AlignLeft [*] Ah, found it! The accepted solution at https://stackoverflow.com/questions/72086632/migrating-to-qt6-pyqt6-what-are-all-the-deprecated-short-form-names-in-qt5 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: You can probably just look at the source code and adjust manually if you don't want to run his whole script.
  • This topic is deleted!

    Unsolved
    13
    0 Votes
    13 Posts
    194 Views
  • Help Assigning Spinbox setting to value

    Solved
    12
    0 Votes
    12 Posts
    2k Views
    L
    @JonB - Eureka! I changed the name of the "position" variable on line 2 variable to axis and amended the rest of the code accordingly. Then I replaced the number [2] on lines 44 & 45 with [self.axis]. The spin box slots now alter the output to the 3D model as I was hoping for - see image. Thank you for you advice and patience - I may be back with some other quandary to solve now that I have had a little success. :)[image: 4f16ab2f-94af-40bb-8900-32989cd58878.png] from PySide.QtGui import * class VertexSelector(QWidget): def __init__(self): super(VertexSelector, self).__init__() ##vars self.depth = 10.0 self.axis = 2 #X=0,Y=1,Z=2 ##Depth object self.lblDepth = QLabel("Depth: Location On Axis") self.sbDepth = QDoubleSpinBox() self.sbDepth.setValue(self.depth) self.sbDepth.setSingleStep(0.5) self.lblAxis = QLabel("Axis: X=0, Y=1, Z=2") self.sbAxis = QSpinBox() self.sbAxis.setValue(self.axis) self.sbAxis.setSingleStep(1) ##button self.btnApply = QPushButton("Apply") self.btnApply.clicked.connect(self.apply) #layout layout = QVBoxLayout() layout.addWidget(self.lblDepth) layout.addWidget(self.sbDepth) layout.addWidget(self.lblAxis) layout.addWidget(self.sbAxis) layout.addWidget(self.btnApply) self.setLayout(layout) ##window self.setWindowFlags(Qt.WindowStaysOnTopHint) self.show() def apply(self): self.depth = float(self.sbDepth.value()) self.axis = (self.sbAxis.value()) shapes = App.ActiveDocument.findObjects("Part::Feature") for sh in shapes: vertexes = [] vertexCount = len(sh.Shape.Vertexes) for vertexIdx in range(vertexCount): try: position = sh.Shape.Vertexes[vertexIdx].Point vertexName="Vertex"+str(vertexIdx+1) App.Console.PrintMessage(vertexName+":") App.Console.PrintMessage(str(round(position[self.axis],2))) if (round(position[self.axis],2) == self.depth): vertexes.append(vertexName) App.Console.PrintMessage("\n") except Exception: App.Console.PrintMessage("Not applicable\n") Gui.Selection.addSelection(sh,vertexes) fselector = VertexSelector()