Skip to content

Qt for Python

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

3.3k Topics 14.4k Posts
  • How to implement text ellipsis effect in QLabel?

    Solved 23 Oct 2024, 20:03
    0 Votes
    3 Posts
    460 Views
    @JonB Thank you very much! Following the example you provided, I successfully rewrote the component in Python, and the ellipsis functionality works perfectly. Moreover, the component fully supports QSS styling as well—it looks fantastic! Thanks again for your help! from PySide6.QtWidgets import QLabel from PySide6.QtCore import Qt from PySide6.QtGui import QFontMetrics class EllipsisLabel(QLabel): def __init__(self, text="", parent=None): super().__init__(parent) self._text = text self.setText(text) def setText(self, text): self._text = text self.updateText() def resizeEvent(self, event): super().resizeEvent(event) self.updateText() def updateText(self): metrics = QFontMetrics(self.font()) elided = metrics.elidedText(self._text, Qt.ElideRight, self.width()) super().setText(elided)
  • Disable python warnings on Qt Creator

    Solved 1 Dec 2021, 08:29
    0 Votes
    3 Posts
    1k Views
    This thead provides more information about disabling specific warnings.
  • This topic is deleted!

    Unsolved 22 Oct 2024, 13:30
    1 Votes
    11 Posts
    166 Views
  • QSliders in PyQt5 vs PySide6

    Unsolved 17 Oct 2024, 20:00
    0 Votes
    9 Posts
    1k Views
    @JonB @SGaist I have tried implementing QThreads. While the GUI does not freeze the response has a lot of inertia, by the time I finish moving the QSlider the app keeps updating the respective graphs and it is pretty annoying to use. I also tried to subclass QSlider and use a QTimer to make the signal emit 200ms after the valueChanged signal have been fired and the results are not good compared to PyQt5. Also, the sliderMoved signal behaves very similarly to valueChanged. Could I get some additional tips? I have tried to inspect the Qt5 and Qt6 implementation of QSlider but I honestly do not even know where to start looking at them. Any help is welcome. Thanks again!
  • This topic is deleted!

    Unsolved 21 Oct 2024, 12:22
    0 Votes
    1 Posts
    7 Views
    No one has replied
  • Eventfilter on text edit not working

    Solved 18 Oct 2024, 13:22
    0 Votes
    13 Posts
    807 Views
    @Nightmaster said in Eventfilter on text edit not working: My eventFilter method was indented two spaces too much. :) Which is one reason I am really not fond of Python....!
  • 0 Votes
    1 Posts
    123 Views
    No one has replied
  • Residual data in QImage after reinstantiating

    Solved 19 Oct 2024, 10:01
    0 Votes
    3 Posts
    175 Views
    Hi, Did you open a ticket to make this known ?
  • 0 Votes
    6 Posts
    446 Views
    Nice ! Glad you found out and thanks for sharing. That said, I would suggest to properly clean that state object.
  • 0 Votes
    9 Posts
    3k Views
    @MrAWD said in TypeError: __init__() missing 1 required positional argument: 'item': TypeError: __init__() missing 1 required positional argument: 'item' Well, I tried and PyQt6 reports same error. So this is not a PySide-only issue. But the PyQt6 gives a surprising clue: jon@ubuntu-22:~/QtTests/PyQt$ python3 multiinherit.py Traceback (most recent call last): File "/home/jon/QtTests/PyQt/multiinherit.py", line 21, in <module> win = MyWindow() ^^^^^^^^^^ File "/home/jon/QtTests/PyQt/multiinherit.py", line 16, in __init__ self.label = myClass("item") ^^^^^^^^^^^^^^^ File "/home/jon/QtTests/PyQt/multiinherit.py", line 10, in __init__ QLineEdit.__init__(self, parent) TypeError: HelperClass.__init__() missing 1 required positional argument: 'item' So although the error is shown beneath QLineEdit.__init__(self, parent) and PySide6 just says __init__() missing 1 required positional, PyQt6 says HelperClass.__init__() missing 1 required positional So it is complaining about HelperClass.__init__() not QLineEdit.__init__().... I am not a regular Python dev so I will leave it at that. UPDATE On a whim/hunch, I tried changing the order of your inheritance to: class myClass(HelperClass, QLineEdit) Lo and behold, this works fine under both PySide & PyQt! Now, it may be you were getting away with something which ought never to have worked on old PySide2. In C++ if you want to multi-inherit from a QObject type and a non-QObject type (not allowed to multi-inherit from QObject publicly) you must place the QObject one first in the list, to keep moc happy (https://doc.qt.io/qt-6/moc.html#multiple-inheritance-requires-qobject-to-be-first). To be fair, that is exactly what you non-working original did. I am finding the opposite is required to keep PyQt6/PySide6 happy here! Check that with the re-arranged order everything else, especially the QLineEdit functionality/signals, work. If so, my finding is that the reverse of what C++/moc wants is required for Py...! Go figure :) P.S. The error might have some relationship to https://forum.qt.io/post/755209 We have hit this issue too. PySide 6.5.0 appears to use the signature of the last super-class that is initialised for both of them. I know you are not using super(), but when it goes wrong in your original order maybe this is related to the "using the last signature encountered". Or, you might want to look at Christian Tismer's answer in https://bugreports.qt.io/browse/PYSIDE-2294 where he suggests combining the two separate __init__()s into a single super().__init__(a_value=a_value, b_value=b_value) You might also report your original code as a "bug" to the PySide folks and see what they have to say. Though the fact that it behaves the same as PyQt may indicate it is not their problem.
  • 0 Votes
    2 Posts
    178 Views
    We are planning to add it, it should appear in 6.8.1 (map part only). Here is the change: https://codereview.qt-project.org/c/pyside/pyside-setup/+/593311
  • Process ended with exit code 3221225477.

    Unsolved 17 Oct 2024, 05:59
    0 Votes
    6 Posts
    2k Views
    I have updated PySide from 6.7.2 to 6.8.0.1 and the issue is fixed. Somehow there is an issue betwenn PySide 6.7.2 and certain windows 11 machines (maybe specific windows version?)
  • Cannot install PySide6 on Python 3.13.0

    Unsolved 18 Oct 2024, 05:49
    0 Votes
    2 Posts
    2k Views
    3.13. will be supported from 6.8.1 onwards.
  • Smart sizing of QScrollArea

    Unsolved 16 Oct 2024, 17:44
    0 Votes
    2 Posts
    216 Views
    In the mean time I have read some other Threads, apparently also having this problem, but I couldn't find a working solution yet. I have discovered the QAbstractScrollArea.SizeAdjustPolicy.AdjustToContents property, but it doesn't seem to change anything. Also, I found that setting content_widget SizePolicy to Fixed will prevent the buttons to shrink. Anyway, here is an updated example, also with the option to remove the buttons: import sys from PyQt5.QtWidgets import ( QAbstractScrollArea, QApplication, QMainWindow, QPushButton, QScrollArea, QSizePolicy, QVBoxLayout, QWidget, ) class MainWindow(QMainWindow): def __init__(self): super().__init__() widget = QWidget() vbox = QVBoxLayout(widget) vbox.addLayout(self._init_static()) self.scrollarea = self._init_scroll() vbox.addWidget(self.scrollarea) self.setCentralWidget(widget) def _init_static(self): vbox = QVBoxLayout() add = QPushButton("Add Button") add.clicked.connect(self.add_button) clear = QPushButton("Clear Buttons") clear.clicked.connect(self.clear_buttons) vbox.addWidget(add) vbox.addWidget(clear) return vbox def _init_scroll(self): content_widget = QWidget() content_widget.setSizePolicy( QSizePolicy.Policy.MinimumExpanding, QSizePolicy.Policy.Fixed ) self.inner_vbox = QVBoxLayout(content_widget) scroll_area = QScrollArea() scroll_area.setWidgetResizable(True) scroll_area.setSizePolicy( QSizePolicy.Policy.MinimumExpanding, QSizePolicy.Policy.Maximum ) scroll_area.setSizeAdjustPolicy( QAbstractScrollArea.SizeAdjustPolicy.AdjustToContents ) scroll_area.setWidget(content_widget) return scroll_area def add_button(self): btn = QPushButton("Remove Button") btn.setMinimumHeight(30) self.inner_vbox.addWidget(btn) btn.clicked.connect(btn.deleteLater) def clear_buttons(self): for child in self.scrollarea.widget().children(): if isinstance(child, QPushButton): child.deleteLater() app = QApplication(sys.argv) window = MainWindow() window.setGeometry(100, 100, 600, 800) window.show() sys.exit(app.exec_())
  • 0 Votes
    4 Posts
    193 Views
    @Mizmas said in Has anyone faced the issue of populating a QComboBox with all installed applications and their icons?: reg_key_path = rf"Installer\Products\{product_id}" You're not supposed to put in {product_id} as a literal string. It's supposed to be a placeholder for an id which identifies your product, else how would it disguise between products/applications with just a fixed string? Code like in the C# GetIconForRoot(string productName) function shown. Have a look at what is there in the Registry. Ohhh, this is Python I guess! I get it, {product_id} is NOT literal! Have a look at what is actually there in regedit. The C# code does GetSubKeyNames(), does it explore downward more than your code? EDIT: Nah, It only has subkeys of lots of hex digits. Is that what your product_id = subkey_name # Use subkey_name (productID) to lookup delivers? I think I have to leave you with tis, I don't know more. You have to go via Win32 code here. Precisely because it's so platform-specific there is every reason to suppose you would have trouble finding example code in anything Qt.
  • pyqt5, cmd, console

    Moved Unsolved 8 Mar 2021, 18:38
    0 Votes
    5 Posts
    633 Views
    @GinaBishop Same answers as above. Did you try @SGaist's suggestions?
  • QToolBox seamless tab title and content

    Unsolved 14 Oct 2024, 21:46
    0 Votes
    1 Posts
    147 Views
    No one has replied
  • How to get the font name as readable text

    Solved 13 Oct 2024, 17:08
    0 Votes
    6 Posts
    428 Views
    @JonB : Thank you. Great tips, all works and I learned a lot. Super, will use your info.
  • 0 Votes
    2 Posts
    299 Views
    No, you have to create that manually.
  • one model, two proxies, two views - Argg!

    Solved 11 Oct 2024, 16:10
    0 Votes
    3 Posts
    353 Views
    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.