Skip to content

Qt for Python

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

3.3k Topics 14.5k Posts
  • How I remove content of data from a row in PySide2 without deleting the row

    Unsolved
    10
    0 Votes
    10 Posts
    859 Views
    JonBJ
    @yashi95 Look at: https://doc.qt.io/qt-5/qtablewidget.html#item https://doc.qt.io/qt-5/qtablewidget.html#itemFromIndex https://doc.qt.io/qt-5/qtablewidget.html#findItems https://doc.qt.io/qt-5/qtablewidget.html#indexFromItem Depending on what you have/what you want map to, any of these may be relevant.
  • How to tell Qt/PySide2 where to look for the qt.conf file on Windows?

    Unsolved pyside2
    4
    0 Votes
    4 Posts
    2k Views
    JonBJ
    @Tony32423 said in How to tell Qt/PySide2 where to look for the qt.conf file on Windows?: Usually this is fine as qt.conf is in the same folder as python.exe I'm sorry I'm not providing any solution here, but this sounds awful! Why would a Qt configuration file be placed in the same directory of the general python.exe program? Something similar happens with PyQt5 in that it doesn't pick up the qt.conf file from the arguments, but it does at least default the locations to its own copy of the qt libs in its site-packages folder. This sounds much better. The qt.conf file should surely be placed somewhere inside Qt stuff.
  • Deleting a specific row from a QFormLayout

    Solved
    3
    0 Votes
    3 Posts
    1k Views
    M
    Thanks SGaist, I'm too new to this to fully understand what you've said. I'm not sure how to set a dynamic property but I have seen references to sender methods - I'll have to do some further reading for that. Also not sure where I'd put the lambda you suggest or how to use QSignalMapper (more reading I guess!). However, I found that by defining the "delBtn" inside the row it belongs to, instead of creating it outside and then adding it, the deleteRow (now renamed to zapRow) slot function operates on its own row. from os import linesep import sys from PySide2 import QtWidgets, QtGui from PySide2.QtCore import Signal, Slot from PySide2.QtGui import QColor, QFont, QPalette, Qt, qBlue from PySide2.QtWidgets import ( QApplication, QFileDialog, QFormLayout, QFrame, QHBoxLayout, QLabel, QLineEdit, QMessageBox, QPushButton, QSpacerItem, QVBoxLayout, ) myList = [ {"name": "mn", "phone": "2806" }, {"name": "ts", "phone": "2800" }, {"name": "mb", "phone": "2801" } ] outRow = QFormLayout() class nestedLayouts(QtWidgets.QWidget): def __init__(self): super().__init__() mainLt = QVBoxLayout() for l in myList: outRow.addRow(delBtn(outRow.rowCount()), newRow(l)) outRow.addRow(addBtn(outRow.rowCount())) mainLt.addLayout(outRow) self.setLayout(mainLt) class delBtn(QPushButton): def __init__(self, row): super().__init__() self.num = row self.setText(f"Delete this row") self.clicked.connect(self.zapRow) @Slot() def zapRow(self): row = outRow.getWidgetPosition(self)[0] print("deleting a row...", row) outRow.removeRow(self) print(f"delBtn {row} deleted, outRow count = {outRow.rowCount()}") class addBtn(QPushButton): def __init__(self, row): super().__init__() self.num = row self.setText(f"Add a row") self.clicked.connect(self.newRow) @Slot() def newRow(self): row = outRow.getWidgetPosition(self)[0] outRow.insertRow(row, delBtn(row), newRow({"name": "?", "phone": "?"})) class newRow(QFormLayout): def __init__(self, pList): super().__init__() self.pList = pList for name, phone in pList.items(): print(name, phone) label = QLabel(name) field = QLineEdit() field.setText(phone) self.addRow(label, field) if __name__ == "__main__": app = QApplication(sys.argv) app.setStyle("windowsvista") nest = nestedLayouts() nest.resize(800, 300) nest.show() sys.exit(app.exec_())
  • Emit is delayed

    Solved
    3
    0 Votes
    3 Posts
    722 Views
    S
    @jeremy_k Thank you very much for the advice. The clues provided did allow me to track down this: So I added Qt::DirectConnection and this now is caught when the button is pressed. Please don't do that! That causes your your slot to run in the GUI thread instead of your Algorithm's thread. The answer appears to be in that thread.
  • Pros and cons of using Qnetwork vs sockets

    Unsolved
    6
    0 Votes
    6 Posts
    744 Views
    SGaistS
    You should not need to.
  • How to configure PYLS for Qt?

    Unsolved
    2
    0 Votes
    2 Posts
    903 Views
    jeremy_kJ
    There are a few options that can be set in the Language Client section of Creator's preferences. Beyond that and the command line arguments, it looks like PYLS uses several configuration files based on which providers it autodetects. I haven't found an easy solution. https://pypi.org/project/python-language-server/
  • [PyQt5 5.15] QListWidgetItem.setSizeHint not working

    Solved
    7
    0 Votes
    7 Posts
    2k Views
    jeremy_kJ
    The behavior is indeed new with 5.15. The change makes it possible to reset the background, foreground, or size hint by passing a default constructed QBrush or QSize. https://github.com/qt/qtbase/commit/96c27eb710a37780e79e09df2ebce1d5e4922c9d
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • Why my QPushButtons are disable on Mac OS X whereas they are enable on Windows?

    Unsolved
    12
    0 Votes
    12 Posts
    1k Views
    S
    https://bugreports.qt.io/browse/QTBUG-85487 It says that it is closed and fix version is 5.15.1.
  • How to QVBoxLayout setFixedWidth

    Unsolved
    5
    0 Votes
    5 Posts
    483 Views
    P
    @SGaist Thanks i will give that a try
  • How to record the video from a webcam in a pyqt5 gui using OpenCV and QThread?

    Unsolved
    4
    0 Votes
    4 Posts
    6k Views
    As_IfA
    @Denni-0 can you help me? I am trying to achieve similar kind of thing but with detections
  • WebGL error on Mac...

    Unsolved
    2
    0 Votes
    2 Posts
    318 Views
    M
    Error in terminal: [9235:86275:0818/192438.831174:ERROR:context_group.cc(153)] ContextResult::kFatalFailure: WebGL2 blacklisted
  • How can i update a widget live

    Unsolved
    4
    0 Votes
    4 Posts
    613 Views
    JonBJ
    @benyeyeye said in How can i update a widget live: Is where i have a singular button in a frame. when pressed i want that button to be removed and 4 different buttons in its place You could do this in a number of ways: To do it literally, you could use a layout's removeWidget() to remove the button and addWidget() to add a bunch of new ones. You could use a button/widget's show/hide/setVisible() methods to hide the first button and show the other ones. You could use a QStackedWidget to swap between one widget having just the first button and another widget having the three other buttons. A QStackedWidget shows only one widget at a time from a collection of widgets.
  • Can't find QColorDialog inside Qt designer

    Unsolved
    3
    0 Votes
    3 Posts
    759 Views
    M
    Alright thanks for the answer!
  • How to track user activity of my PyQt software with Google Analytics?

    Unsolved
    2
    0 Votes
    2 Posts
    564 Views
    JKSHJ
    You can import Google's native Python API into your Qt software: https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/installed-py
  • How to trigger a def from a QCombobox

    Unsolved
    2
    0 Votes
    2 Posts
    238 Views
    P
    @Penguin-Powered-Apps I think i may be right in thinking that this should get the job done combobox.currentIndexChanged.connect(doSomething) Thanks
  • WebView crashes when setUrl is called inside a thread

    Solved pyside2 qt for python python pyside
    10
    0 Votes
    10 Posts
    1k Views
    SGaistS
    I highly encourage you to learn the signals and slots paradigm. Qt is an asynchronous framework which means that you may not need an additional thread depending on what you need to process and how you process it. Did they warm you about the nuclear footgun that it can be ? ;-)
  • How to generate a new label each time a button is pressed?

    Unsolved
    2
    -1 Votes
    2 Posts
    1k Views
    JonBJ
    @ndkt is there a way I can generate a new label each time a button is pressed. Yes. In your slot (just like anywhere else) you can create widgets dynamically by newLabel = QLabel() or similar, and then add the new widget wherever appropriate somewhere in your widget hierarchy. Or is there another way that doesn't use text label that I should use? You could represent these via individual QLabels, and add those onto, say, a QVerticalLayout. However, there are many other ways, perhaps better suited. You could, say, add them onto a QTableWidget via QTableWidgetItem(const QString &text), or use a QGridLayout which allows the adding of rows/columns, or you might pick a QListWidget to store/show them as a list in a single widget, which would be my first inclination. Especially if there are going to be a large number of items, you don't want to create a large number of individual QLabels, speed & memory.
  • 0 Votes
    3 Posts
    583 Views
    B
    Hey, thanks for the reply. Yes, you are right, it's quite outdated. However I'm writing a Plug-in for a software called Nuke. That Plug-in needs to work in older versions too. The newest version is Nuke 12. But the Plug-in has to also work with Nuke 7. Nuke 7 however comes with Python 2.6.5, PySide 1.0.9, Qt version 4.7.2. So I don't really have much of a choice. That's why I'm asking, if there is any other way to get the information where something will be dropped. Maybe someone who is more experienced than me has a better idea, but the only idea I currently have, if the above is not possible, is to accept the drop and if it's invalid to move the entire subtree back to it's previous position. But that's a solution that I'd like to avoid. In any case thanks for the reply and if someone has a better idea than me I'd really like to hear it.
  • 0 Votes
    5 Posts
    6k Views
    SGaistS
    I do not know how fast your method is, but you usually do not start doing animation within the constructor of a widget. Until the constructor is done and the show event is called, there's no physical presence of the widget. AFAIK it is best to construct all your GUI pieces and once done trigger your long operation that should also show an animation. If you really want to do that from the constructor, use a single shot timer with a 0 delay that will then trigger as soon as possible once the event loop is running to call your method.