Skip to content

Qt for Python

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

3.3k Topics 14.5k Posts
  • 0 Votes
    11 Posts
    1k Views
    @memyselfandi Important is to not to mix different Qt versions
  • How to acquire the frame colour?

    Unsolved 12 May 2025, 22:09
    0 Votes
    1 Posts
    435 Views
    No one has replied
  • Pyqt5 : finding the selection in a qTextEdit

    Unsolved 12 May 2025, 14:22
    0 Votes
    2 Posts
    302 Views
    Hi and welcome to devnet, Which position do you mean ? In widget coordinates ? The number of chars from the start of the text ?
  • 0 Votes
    5 Posts
    1k Views
    14/5000 So in the end, in what way was it solved?
  • Unable to run a Pyside6 application in QtCreator

    Solved 4 Jan 2023, 21:13
    0 Votes
    7 Posts
    2k Views
    I know this post is old, but in my case when I got this error, I was missing the tomlkit module in my python installation.
  • 0 Votes
    4 Posts
    603 Views
    After doing some digging I found this thread. My Python project on Raspberry Pi OS requires PySide6==6.8.3 or later which depends on glibc 2.39 but RPiOS only provides 2.36. I tried building from source and containerising it with chroot but neither produced the proper result. I'm going try switching to Ubuntu Server 24.04 for Raspberry Pi and hope for the best seeing as it will have the proper glibc version. If I don't report back within the week assume that it worked.
  • Main window always opens on 'incorrect' monitor

    Solved 5 May 2025, 16:18
    0 Votes
    4 Posts
    476 Views
    Hi All, first things first, I am stuck on python 3.7.3. I tried upgrading to the latest supported version of pyside6 which seems to be 6.5.3. This seems to have fixed my issue. I did make a python version of @CassD script and using pyside 6.2.4, I get the following output manufacturer : model : Screen Name : LF24T450F Screen Size : PySide6.QtCore.QSize(1920, 1080) While using pyside 6.5.3, I get the following manufacturer : Samsung Electric Company model : LF24T450F Screen Name : LF24T450F (1) Screen Size : PySide6.QtCore.QSize(1920, 1080) manufacturer : Samsung Electric Company model : LF24T450F Screen Name : LF24T450F (2) Screen Size : PySide6.QtCore.QSize(1920, 1080) So it seems version 6.2.4 does have some issues detecting screens. In any case, my issue is now resolved, thanks.
  • Get XY Coordinates of QTextCursor

    Solved 6 May 2025, 17:36
    0 Votes
    3 Posts
    380 Views
    @IgKh Thanks so much for your direction. That was exactly what I needed! Here is the code I used: #####determine the cursor position to scroll the scrollArea as needed #get the blockBoundingRect of the block that holds the QTextCursor blockRect = self.doc.documentLayout().blockBoundingRect(self.cur.block()) #get the QTextLine that holds the QTextCursor cursorLine = self.cur.block().layout().lineForTextPosition(self.cur.positionInBlock()) #get the QTextLine's naturalTextRect so we can get the Y center of the QTextCursor self.cursorLineRect = cursorLine.naturalTextRect() #translate the cursorLineRect to the blockRect self.cursorLineRect.translate(blockRect.x(),blockRect.y()) #get the approximate X position of the cursor cursorToX = cursorLine.cursorToX(self.cur.positionInBlock(), QTextLine.Edge.Leading) #create a QPointF from the cursorToX posistion and the center of the CursorLineRect self.cursorPoint=QPointF(float(cursorToX[0])+blockRect.x(),self.cursorLineRect.center().y()) #instruct the QScrollArea to keep the QPointF visible with 100px padding self.main_window.scrollArea.ensureVisible(self.cursorPoint.x(), self.cursorPoint.y(),100,100) Then to confirm my computation was correct I painted self.cursorPoint using painter.drawPoint(self.cursorPoint) . You can see the little red dot following the text cursor in the screenshot below. Your guidance solved my problem 100% [image: 76f8252d-e31d-406b-8d53-f90af5c226ad.JPG]
  • 0 Votes
    4 Posts
    685 Views
    I made a batch script that I run every time I detect that the .qrc (or .ui) files have changed. It's all automated before launching the application.
  • PySide6 QLineSeries doesn't plot correctly

    Unsolved 17 Apr 2025, 07:17
    0 Votes
    3 Posts
    328 Views
    @JonB said in PySide6 QLineSeries doesn't plot correctly: this should not be a PySide6/Python issue Yes, https://bugreports.qt.io/browse/PYSIDE-3083 For it seems not so robust, I tries PythonQwt, but it is not complete, e.g. QwtArraySeriesData is not ported for python. Now I'm using matplotlib with qtagg backend, it works fine. It's said that QtGraphs is going to replace QtCharts, but the API in C++ is not complete so far, I'll follow it. Thanks
  • FocusOutEvent get stuck in a loop

    Unsolved 22 Apr 2025, 12:20
    0 Votes
    7 Posts
    791 Views
    I've been digging through this some more and what appears to be happening is when I press tab to leave line_edit1 it goes to my focusOutEvent of CustomLineEdit1 and sets the focus back to line_edit1 but it is like the focus has also transferred over to line_edit2 so when the super().setfocus of line_edit1 happens then line_edit2 sees that and fires off it's focusOutEvent and this keeps going back and forth since they each see the focus leaving their respective line edits. If I remove the super().setfocus from the else of line_edit2 things work because there is nothing telling it to take the focus back away from line_edit1. The problem with this is that after I do go on to line_edit2 and tab out of it to go to line_edit3, with out the super().setfocus in the else the focus does not return to line_edit2 like I need it to. The event.accept() have had no effect. Unless there is something else going on here it seems like the focus should never make it to line_edit2 if I'm intercepting the focusOutEvent of line_edit1 and changing it.
  • Defer Resize Event due to expensive resize method.

    Unsolved 2 Apr 2025, 13:50
    0 Votes
    5 Posts
    407 Views
    @SimonSchroeder I think I'm already doing what you're suggesting. I've implemented a custom resizeEvent(...) that calls timer.start() on a single shot timer every time a ResizeEvent is recieved. This also resets the timer if an event is received shortly after another. And then I perform the actual resize of the widget when the timer times out. ChatGPT Suggested using this: import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel from PyQt6.QtCore import QTimer, QAbstractNativeEventFilter from PyQt6.QtGui import QGuiApplication class NativeResizeFilter(QAbstractNativeEventFilter): """Listens for native window events to detect when resizing stops.""" def __init__(self, callback): super().__init__() self.callback = callback # Function to call when resize stops def nativeEventFilter(self, eventType, message): from ctypes import windll if eventType == "windows_generic_MSG": msg = int.from_bytes(message[:8], byteorder=sys.byteorder) WM_EXITSIZEMOVE = 0x0232 # Windows event when resizing stops if msg == WM_EXITSIZEMOVE: self.callback() return False, 0 It seems (!) to be potentially possible to do the deferred scaling using events on Windows. I've also looked into dealing with NativeEvents on MacOS and Linux however, it seems to be rather tedious. So as for now, I've opted to go with the timer and maybe do the fancy resizing if I have the time to spare. AliSot2000
  • This topic is deleted!

    Unsolved 20 Apr 2025, 07:10
    0 Votes
    1 Posts
    9 Views
    No one has replied
  • QMediaPlayer with reduced video resolution

    Moved Unsolved 14 Apr 2025, 23:27
    0 Votes
    4 Posts
    296 Views
    So the backend uses ffmpeg however I don't think that you currently can delegate the resizing to it. You could do it in a sink though but I am unsure about the performance of it.
  • Hiding viewer panel vs window maximization

    Moved Unsolved 10 Apr 2025, 08:55
    0 Votes
    2 Posts
    216 Views
    When the state of self.was_maximized changed, the second if in adapt_viewer_panel is not working as expected. Adding self.was_maximized = not hide_viewer_panel to the else statement worked for me: def adapt_viewer_panel(self): if hide_viewer_panel: self.setFixedWidth(200) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) self.viewer_panel.hide() else: self.setMinimumWidth(1500) self.setMaximumWidth(16777215) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) self.viewer_panel.show() self.was_maximized = not hide_viewer_panel self.updateGeometry() self.adjustSize() self.repaint() if not hide_viewer_panel and self.was_maximized: self.showMaximized()
  • hiding a QLabel at default

    Unsolved 13 Apr 2025, 12:24
    0 Votes
    2 Posts
    413 Views
    Hi and welcome to devnet, How are you setting up your label ? On a side note, I would recommend you take the time to re-evaluate your architecture. Your chain of dialogs is currently pretty brittle. There are other ways to switch from one widget to another that does not involve creating a new widget every time. Check for example QStackedWidget. You might want to also consider QMainWindow which provides a status bar. Depending on the error you might want to consider a QMessageBox using the appropriate level of urgency to show the message.
  • This topic is deleted!

    Unsolved 12 Apr 2025, 06:17
    0 Votes
    1 Posts
    11 Views
    No one has replied
  • 0 Votes
    2 Posts
    284 Views
    I solved the problem by using qtbase 6.9 instead of 6.10. However there might be other subtle reasons that I overlooked(?).
  • Could not update timestamps for skipped samples.

    Unsolved 18 Mar 2025, 09:24
    0 Votes
    7 Posts
    975 Views
    @SGaist I get it, thx, I will try.
  • 0 Votes
    1 Posts
    231 Views
    No one has replied