Skip to content

Qt for Python

For discussion and questions about Qt for Python (PySide 2)

2.6k Topics 13.2k Posts
  • 0 Votes
    6 Posts
    55 Views
    SGaistS

    @sontrantls that's the trick: does the utility do something at a lower level to communicate with this printer ?

  • Impossible to display an Icon in a QtTableView

    Unsolved
    8
    0 Votes
    8 Posts
    109 Views
    SGaistS

    @faldo1 Are you sure the file was loaded successfully ?

  • setItemDelegateForColumn causes app to crash

    Solved
    4
    0 Votes
    4 Posts
    47 Views
    SGaistS

    @George55978 Nice ! For once, the minimal was a bit too minimal ^^

    Happy coding !

  • 0 Votes
    9 Posts
    96 Views
    E

    @jeremy_k I understand your point. On my list of todo's is to put together a small file with all the relevant information. Unfortunately I'm in the midst of some massive reactoring which I want to complete before I create that small file. With luck I'll get to that within a week. In the mean time here is the code of the function which has the addItem which raises the exception. I understand this code will not work even after the initial addItem issue is solved. I'll fix that once the initial problem is resolved.

    def plot_to_gui_from_pyqtgraph_ai_assistant(self, plot_item): print(f"DEBUG -- at top of plot_to_gui_from_pyqtgraph_ai_assistant {plot_item=}") # Create a GraphicsLayoutWidget to place your pyqtgraph plot onto widget_plot = GraphicsLayoutWidget() # Add your plot_item to the GraphicsLayoutWidget widget_plot.addItem(plot_item) self.tab_plot_scroll_area.setWidget(widget_plot) # plot_item_clone = deepcopy(plot_item) # Repeat the process for the Gallery tab widget_gallery = GraphicsLayoutWidget() # widget_gallery.addItem(plot_item_clone) self.tab_gallery_layout.addWidget(widget_gallery) # Add a spacer at the end to push plots to the top spacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) self.tab_gallery_layout.addItem(spacer)
  • Can we prevent automatic video flushing with QMediaPlayer?

    Unsolved
    2
    0 Votes
    2 Posts
    29 Views
    SGaistS

    Hi,

    Having pinged the ticket is a good first step.

    The next you can to is test drive the proposed patch. The one named "Propose API". That way, you can see if it does what you need, and then comment on the patch itself to help it move forward.

  • Getting as a problem a parent object in my script

    Moved Unsolved
    7
    0 Votes
    7 Posts
    120 Views
    G

    i have a problem with CCI.Convert

  • 0 Votes
    15 Posts
    182 Views
    V

    @jsulm Thank you for all the suggestions and guidance. I have implemented it successfully.

  • How to dymanically resize the heigh of my CustomQWidget

    Unsolved
    3
    0 Votes
    3 Posts
    49 Views
    V
    class CustomQWidget (QWidget): """Custom Qt Widget to be transformed to an item for a QListWidget""" def __init__ (self, parent = None): super(CustomQWidget, self).__init__(parent) self.textQVBoxLayout = QVBoxLayout() self.txtNameQLabel = QLabel() self.subTextQHBoxLayoutUp = QHBoxLayout() self.subTextQHBoxLayoutBot = QHBoxLayout() self.txtAuthorQLabel = QLabel() self.txtDateQLabel = QLabel() self.txtContextQLabel = QLabel() self.txtTypeQLabel = QLabel() self.txtClassQLabel = QLabel() self.codeQVBoxLayout = QVBoxLayout() self.codeQVBoxLayout.addStretch() self.txtCodeQLabel = QLabel()#QLabel to show/hide self.txtCodeQLabel.setVisible(False) self.codeQVBoxLayout.addWidget(self.txtCodeQLabel) self.subTextQHBoxLayoutUp.addWidget(self.txtNameQLabel) self.subTextQHBoxLayoutUp.addWidget(self.txtAuthorQLabel) self.subTextQHBoxLayoutUp.addWidget(self.txtDateQLabel) self.subTextQHBoxLayoutBot.addWidget(self.txtContextQLabel) self.subTextQHBoxLayoutBot.addWidget(self.txtTypeQLabel) self.subTextQHBoxLayoutBot.addWidget(self.txtClassQLabel) self.textQVBoxLayout.addLayout(self.subTextQHBoxLayoutUp) self.textQVBoxLayout.addLayout(self.subTextQHBoxLayoutBot) self.upQHBoxLayout = QHBoxLayout() self.copyButton = QPushButton('Copy') self.codeViewbutton = QPushButton('View code')#Trigger button to show/hide txtCodeQLabel self.codeViewbutton.clicked.connect(functools.partial(self.showHideCode, self.txtCodeQLabel)) self.upQHBoxLayout.addWidget(self.copyButton) self.upQHBoxLayout.addWidget(self.codeViewbutton) self.upQHBoxLayout.addLayout(self.textQVBoxLayout, 1) self.globalLayout = QVBoxLayout() self.globalLayout.addLayout(self.upQHBoxLayout) self.globalLayout.addLayout(self.codeQVBoxLayout) self.globalLayout.addStretch() self.setLayout(self.globalLayout) # setStyleSheet self.txtNameQLabel.setStyleSheet('''color: rgb(255, 128, 64);''') self.txtAuthorQLabel.setStyleSheet('''color: rgb(128, 128, 128);''') def setTxtName (self, text): self.txtNameQLabel.setText(text) def setTxtAuthor (self, text): self.txtAuthorQLabel.setText(text) def setTxtDate (self, text): self.txtDateQLabel.setText(text) def setTxtContext (self, text): self.txtContextQLabel.setText(text) def setTxtType (self, text): self.txtTypeQLabel.setText(text) def setTxtClass (self, text): self.txtClassQLabel.setText(text) def setTxtCode (self, text): self.txtCodeQLabel.setText(text) def getListItem (self, item): self.item = item def showHideCode(self, label): if label.isVisible(): label.setVisible(False) self.item.setSizeHint(self.sizeHint()) else: label.setVisible(True) self.item.setSizeHint(self.sizeHint()) class CreateUI(QWidget): def __init__(self): super().__init__() root_dir ='D:/_vexGraft/' json_disk_file = 'D:/_vexGraft/vexgraft.json' main_layout = QVBoxLayout(self) top_layout = QHBoxLayout(self) bot_layout = QHBoxLayout(self) self.label = QLabel(root_dir) top_layout.addWidget(self.label) self.button = QPushButton('Save Selected') self.button.clicked.connect(functools.partial(self.save_selected,json_disk_file)) bot_layout.addWidget(self.button) main_layout.addLayout(top_layout) self.main_widget = self.populateMainLayout(json_disk_file)#QListWigdet with items main_layout.addWidget(self.main_widget) main_layout.addLayout(bot_layout) def populateMainLayout(self,json_disk_file): """Populate QListWidget with configured CustomQWidget from json entry""" listing = QListWidget() current_data = self.openJson(json_disk_file) for entry in current_data: myCustomQWidget = CustomQWidget() myCustomQWidget.setTxtName(str(entry['name'])) myCustomQWidget.setTxtDate(str(entry['date'])) myCustomQWidget.setTxtAuthor(str(entry['author'])) myCustomQWidget.setTxtContext(str(entry['context'])) myCustomQWidget.setTxtType(str(entry['type'])) myCustomQWidget.setTxtClass(str(entry['class'])) myCustomQWidget.setTxtCode(str(entry['snip'])) q_widgetitem = QListWidgetItem(listing) q_widgetitem.setSizeHint(myCustomQWidget.sizeHint()) myCustomQWidget.getListItem(q_widgetitem)#get the QListWidgetItem receiveing the CustomQWidget instance listing.addItem(q_widgetitem) listing.setItemWidget(q_widgetitem, myCustomQWidget) return listing

    With this new code I attempt to get the corresponding QListWidgetItem in the CustomWidget instance.
    Now when I push the'ViewCode' button the code appear and the size QListWidgetItem is refresh.
    New issue : when I click again on the button the text of the QLabel is hidden but the QListWidgetItem doesn't refresh its size correctly

  • Need help with QSqlModel - PySide6

    Moved Solved
    14
    0 Votes
    14 Posts
    225 Views
    SGaistS

    I wonder if it is something related to Python's garbage collection.

  • Using aiohttp with QtAsyncio

    Unsolved
    8
    0 Votes
    8 Posts
    268 Views
    Q

    @Faerbit This seems to be a known problem due to the fact, and there seems to be a library to address this problem:qasync. The following is a minimal sample I have assembled to use async/await aiohttp in a PySide6 app. It worked on my computer.

    import asyncio import aiohttp import qasync from PySide6.QtCore import Qt from PySide6.QtWidgets import QApplication, QPushButton, QMainWindow, QVBoxLayout, QWidget class MainWindow(QMainWindow): def __init__(self): super().__init__() self.resize(600, 400) self.central_widget = QWidget() self.layout = QVBoxLayout() self.button = QPushButton("Fetch Data") self.button.clicked.connect(lambda : asyncio.create_task(self.fetch_data())) self.layout.addWidget(self.button, alignment=Qt.AlignCenter) self.central_widget.setLayout(self.layout) self.setCentralWidget(self.central_widget) async def fetch_data(self): self.setWindowTitle("Loading...") async with aiohttp.ClientSession() as session: async with session.get('https://reqres.in/api/users?delay=5') as response: if response.status == 200: text = await response.text() print(text) self.setWindowTitle("Got") app = QApplication([]) window = MainWindow() window.show() loop = qasync.QEventLoop(app) with loop: loop.run_forever()
  • This topic is deleted!

    Unsolved
    4
    0 Votes
    4 Posts
    35 Views
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    11 Views
    No one has replied
  • Keep Checking for Live Video Stream

    Solved
    16
    0 Votes
    16 Posts
    311 Views
    V

    @JonB Thank you for all the inputs, I somehow managed to play and stop the video and also display error message.

  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    7 Views
    No one has replied
  • 0 Votes
    14 Posts
    172 Views
    SGaistS

    @jsulm It's not a python crash, it's a C++ crash.

    It happens because the application tries to access already freed resources.

    On the technical side, I think that there's something that might be off with Python/C++ memory management at play. Technically, the items are stored in a temporary list which itself is then stored in an item. That should make it not temporary anymore and thus keep a reference to the items. However, it looks like it does not work that way. It might be due to the nature of the objects stored there.

    That said, the simple fix in this case is to use a list of strings rather than a list of QListWidgetItem. You can then leverage the addItems function so you have one less loop in your code.

  • Anything Related to Gamepad

    Solved
    3
    0 Votes
    3 Posts
    77 Views
    V

    @SGaist Thanks but the problem is it doesn't allow to reconnect to the joystick if the joystick is disconnected while the Qt program is running and the joystick is detect at /dev/input/js0, which can only be accessed using struct module. I have implemented this using struct module inside a QThread to read the data and again reconnect.

  • pytest Segmentation fault with PySide6 (6.7.0)

    Solved
    5
    0 Votes
    5 Posts
    113 Views
    S

    @friedemannkleint
    Thanks a lot for your time. It appears to be a gap in my knowledge :)

  • Create QUiLoader before QUiApplication?

    Unsolved
    13
    0 Votes
    13 Posts
    190 Views
    S

    @JonB Ahhh okay, in that case I completely agree that the uic method is far superior. I will proceed with this approach.

    Many thanks for your patience & thorough answers, I only started coding a few months ago so advice like this is invaluable to me! Much appreciated.

  • Weird behaviour of QBarSeries

    Unsolved
    2
    0 Votes
    2 Posts
    66 Views
    T

    @TommasoFurieriDO i solved it calling self.polsChart.createDefaultAxes() inside the update_chart(self) function.

    I actually don't know if this is actually needed or if there is a better way to do so.

  • How to get WinID handle as pointer in pyside6

    Unsolved
    1
    0 Votes
    1 Posts
    40 Views
    No one has replied