Python Forum
Why QListWidget doesn't show new line?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why QListWidget doesn't show new line?
#1
In Qt Designer, I created a form, on which I placed a QlistWidget to display the processing progress:

from PyQt5 import QtWidgets, uic
from Database import Manager
from MyLib import Events, GUI
import Forms, General

class Form(QtWidgets.QWidget):

    def __init__(self, parent: QtWidgets.QMainWindow):
        QtWidgets.QWidget.__init__(self)
        
        ClassForm, _ = uic.loadUiType(Forms.Directory + 'CreateDatabase.ui')    
        self.ui = ClassForm()
        self.ui.setupUi(self)
        self.parent = parent
        
        #name of form
        self.setWindowTitle('Form for creating database')
        self.widget = QtWidgets.QWidget(self)
         
        layoutV = QtWidgets.QVBoxLayout()
        layoutV.addWidget(self.ui.label)
        layoutV.addWidget(self.ui.ButtonCreateDatabase)
        layoutV.addWidget(self.ui.MessageList)
        
        self.widget.setLayout(layoutV)
        self.setLayout(layoutV)
           
        self.ui.ButtonCreateDatabase.clicked.connect(self.CreateDatabase)
  
    ...
        
    def event(self, current_event: Events.EventForMessageList) -> bool:
        if current_event.type() !=  General.type_event:
            return False
         
        current_object = self.ui.MessageList
        current_object.addItem(current_event.message)
        return True
1. The form is perfectly created.
2. During execution of my procedure, events arrive to form.
3. They are processed without errors, including line: current_object.addItem(current_event.message)

, but no new lines appear on dialog form, in QListWidget. It always remains completely empty.
Why?
Reply
#2
I animate the interface with this code (executed after receiving the event):
q_app = QtWidgets.QApplication.instance()
q_app.processEvents();
Moreover, the processing is finished and the interface should be rendered without any additional actions, but the list field remains empty.

The funny thing is that the number of invisible items in the list is growing! This code returns an ever-increasing value:
quantity = self.ui.MessageList.count()
Reply
#3
self.ui.MessageList.item(quantity-2).text()
returns the correct value! That is, the list actually stores valid data!


I found a bug!!!

It is necessary to change the shape a little bit in size and the elements begin to appear :) But I "revive" the form with:
q_app = QtWidgets.QApplication.instance()
q_app.processEvents();
How to revive the form?
Reply
#4
This is the correct code:
class MyThread(QtCore.QThread):
    def __init__(self, parent=None):
        QtCore.QThread.__init__(self, parent)
        
    def run(self):
        for i in range(1, 11):
            self.sleep(1)
            
            # Передача данных из потока через событие
            Events.message_error(str(i) + " Hop, Hey! La-la-ley!")

class MyList(QtWidgets.QListWidget):
    def __init__(self, parent=None):
        QtWidgets.QListWidget.__init__(self, parent)

    def customEvent(self, current_event: Events.EventForMessageList):
        if current_event.type() != General.type_event:
            return False
        
        self.addItem(current_event.message)
                            
class Form(QtWidgets.QWidget):
    def __init__(self, parent):
        QtWidgets.QWidget.__init__(self)
         
        #name of form
        self.setWindowTitle('Form for creating database')
        
        self.label = QtWidgets.QLabel('Обработка создания базы данных')
        self.ButtonCreateDatabase = QtWidgets.QPushButton("Создать")
        self.MessageList = MyList()
          
        self.layoutV = QtWidgets.QVBoxLayout()
        self.layoutV.addWidget(self.label)
        self.layoutV.addWidget(self.ButtonCreateDatabase)
        self.layoutV.addWidget(self.MessageList)
          
        self.setLayout(self.layoutV)
            
        self.thread = MyThread()
        
        self.ButtonCreateDatabase.clicked.connect(self.on_clicked)

    def on_clicked(self):
        General.generate_type_event()
        General.event_receiver = self.MessageList
        
        self.thread.start()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get the color name of qlistwidget? flash77 5 1,193 Aug-13-2023, 07:01 PM
Last Post: flash77
  QListWidget, no item was selected flash77 4 925 Aug-02-2023, 09:31 AM
Last Post: Axel_Erfurt
  GUI Problem / call another function / fill QListwidget flash77 5 836 Jul-30-2023, 04:29 PM
Last Post: flash77
  [PyQt] populate a QListWidget devilonline 1 1,525 Apr-10-2023, 02:52 AM
Last Post: deanhystad
Question [PyQt] CSS Styling for a QLabel inside a QListWidget Alfalfa 2 5,053 Nov-30-2020, 02:59 AM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020