Results 1 to 20 of 20

Thread: QListWidget SIGNAL Problem

  1. #1
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QListWidget SIGNAL Problem

    Hello, i have a problem with a listwidget i have created inside a QToolBox page, if doesnt emit signals, i can select the items but it doesnt emit itemDoubleClicked or itemClicked or itemActivated, i have tried with mouse and keyboard without luck, i have installed an event filter and do a print to every event it pass and i get no event in mouse click, double click, or keyboard enter, but i can navigate through items with keyboard or mouse, anyone has any idea what can be the problem here? or any better way that the eventfilter to debug it? Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget SIGNAL Problem

    Could we see some code please?

  3. #3
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget SIGNAL Problem

    yes, sorry, this is pyqt code but i think it is very readable:

    Qt Code:
    1. self.opePendientesPage = QtGui.QWidget()
    2. self.opePendientesPage.setGeometry(QtCore.QRect(0,0,171,260))
    3. self.opePendientesPage.setObjectName("opePendientesPage")
    4.  
    5. self.operacionesPendientesListWidget = QListWidget(self.opePendientesPage)
    6. self.operacionesPendientesListWidget.setFocusPolicy(QtCore.Qt.WheelFocus)
    7. self.operacionesPendientesListWidget.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
    8. self.operacionesPendientesListWidget.setObjectName("operacionesPendientesListWidget")
    9.  
    10. self.vboxlayout4 = QtGui.QVBoxLayout(self.opePendientesPage)
    11. self.vboxlayout4.setSpacing(1)
    12. self.vboxlayout4.setContentsMargins(0,1,1,1)
    13. self.vboxlayout4.setObjectName("vboxlayout4")
    14. self.vboxlayout4.addWidget(self.operacionesPendientesListWidget)
    15. self.toolBox.addItem(self.opePendientesPage,QtGui.QIcon(":/images/operaciones_pendientes.png"),"")
    16.  
    17. self.connect(self.operacionesPendientesListWidget, SIGNAL("itemDoubleClicked(QListWidgetItem)"), self.cargarPendiente)
    To copy to clipboard, switch view to plain text mode 

    I have in other pages of the toolbox QPushButtons that launch clicked() signal, i dont know what can be the problem. I have pasted the itemDoubleClicked signal but i have tried with ItemClicked and with itemActivated with the same results.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget SIGNAL Problem

    Hmmm... correct me if I'm wrong, but your connect statement misses a SLOT() argument...

  5. #5
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget SIGNAL Problem

    No, in PyQt only need the SLOT() when connecting if you are to launch an internal slot of QT (like accept() or reject()) but not for self defined functions, the working code for the buttons is this:

    Qt Code:
    1. self.connect(self.okButton, SIGNAL("clicked()"), self.accept)
    To copy to clipboard, switch view to plain text mode 

    this go the accept function inside the class. But i cant get the signals of the listwidget.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget SIGNAL Problem

    So cargarPendiente is the name of a function? Can we see it? I understand it doesn't get called, correct? Does the list widget itself work? Can you click it or scroll it?

  7. #7
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget SIGNAL Problem

    The function never is called, the listwidget works as expected, i can scroll, select items and navigate between them with keyboard arrows or mouse clicks. The function only does a print actually to test the signal but it is never emitted.

    Qt Code:
    1. def cargarPendiente(self, listaItem):
    2. print "ok"
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget SIGNAL Problem

    If the list works, then signals are delivered. Try connecting some signal to a slot that already exists in Qt, like QCoreApplication::quit(). If it works, it means the problem is not with the list widget but with your slot. One more thing - don't you have to flush the output stream for the printed text to become visible on the terminal like in other languages?

  9. #9
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget SIGNAL Problem

    I have tested connect to the quit() SLOT and it doesnt works either, yes in python this is the way to print to console. you can do:

    print "Variable Name: " + variableName + " Variable Name2: " + variableName2
    or:
    print "Variable Name: %s, Variable Name2: %s" % (variableName, variableName2)

    to do string formating if you want. wysota i have tested installing an eventfilter to this and print every event.type() that pass the filter, i have not received any event of mouse or keyboard handling.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget SIGNAL Problem

    Then you did something wrong, because obviously events get delivered, as the list widget works. See if you didn't do any spelling mistakes, that's a common problem with python. And about print, I was asking if you need to add a newline character at the end to flush the output or does Python add it for you itself. In doubt use qDebug() instead of print.

    By the way, what did you install thise event filter on? the widget or its viewport?

    Oh... and it could help if you provided more code.

    One more thing - check if connect() returns true or false.

  11. The following user says thank you to wysota for this useful post:

    skuda (8th December 2007)

  12. #11
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QListWidget SIGNAL Problem

    yes print add newlines at the end of every print statement, i use very much print to debug inside this application.

    Qt Code:
    1. def eventFilter(self, object, event):
    2. print event.type()
    3. return QMainWindow.eventFilter(self, object, event)
    4.  
    5. in _init_ function i install the eventfilter with:
    6. self.operacionesPendientesListWidget.installEventFilter(self)
    To copy to clipboard, switch view to plain text mode 

    it prints this events:
    when i mouseover: 129
    when i left the widget: 12, 77, 12, 25, 9
    when i doubleclick or click i get no signal.

    i have found a detail, i get the signals when i enter in the toolbox but i am filtering listwidget, can be the problem that toolbox intercepts the mouse events? but i can select items and move between them with cursors ¿?

    the way i create the items:

    Qt Code:
    1. def dejarPendiente(self, codigoCliente, numeroIdentificador):
    2. hora = QTime().currentTime().toString(FORMATO_HORA)
    3. if self.sender() == self.ventaWidget:
    4. item = QListWidgetItem(QIcon(":/images/pantalla_ventas.png"), self.tr("%1 %2").arg(codigoCliente).arg(hora))
    5. item.setData(Qt.UserRole, QVariant(numeroIdentificador))
    6. self.operacionesPendientesListWidget.insertItem(0, item)
    To copy to clipboard, switch view to plain text mode 

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget SIGNAL Problem

    The toolbox shouldn't be filtering the list widget and even if it did, it wouldn't steal its events so eventually they'd reach the listview. The listview itself installs an event filter on its viewport, but this is not important right now. Your problem is that emited signal doesn't trigger your slot. Again, could you check if connect returns true or false?

  14. #13
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default

    returns True

    do i have any way to see the signals emitted by the ListWidget?
    Last edited by wysota; 7th December 2007 at 23:12. Reason: Posts merged

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget SIGNAL Problem

    You can use a signal spy (for example the one that comes with QTestLib).

    I'm pretty sure the list widget is fine and there is some stupid problem we don't see with your slot.

  16. #15
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget SIGNAL Problem

    signal spy seems not to be wrapped in PyQt but i have found anything interesting, i have changed my code to use qlistview and a oversimplified qabstractlistmodel subclass, here you have the relevant code:

    Qt Code:
    1. self.listView = QListView(self.opePendientesPage)
    2. self.connect(self.listView, SIGNAL("doubleClicked(QModelIndex)"), self.cargarPendiente)
    3. self.listmodel = listModel()
    4. self.listView.setModel(self.listmodel)
    5.  
    6. class listModel(QAbstractListModel):
    7. def __init__(self, parent=None):
    8. super(listModel, self).__init__(parent)
    9. self.nullvariant = QVariant()
    10.  
    11. def rowCount(self, index=QModelIndex()):
    12. return 1
    13.  
    14. def data(self, index, role=Qt.DisplayRole):
    15. row = index.row()
    16. if not index.isValid():
    17. return self.nullvariant
    18. if role == Qt.DisplayRole or role == Qt.EditRole:
    19. return QVariant(QString("TEST"))
    20. else:
    21. return self.nullvariant
    To copy to clipboard, switch view to plain text mode 

    all the other code is exactly as before and i have put the new listview in the same toolbox page where was the qlistwidget but this works, when i doubleclick in TEST string inside the qlistview i have my function executed so we have any ghost here

  17. #16
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget SIGNAL Problem

    ok i have made a small sample with the problem i have with listwidget, the connects prints true (anyway python do an exception if the object or slot names dont exists), this one is the complete code and it doesnt works either.

    Qt Code:
    1. #!/usr/bin/env python
    2. from PyQt4.QtCore import *
    3. from PyQt4.QtGui import *
    4.  
    5. class ListWidgetTest(QDialog):
    6. def __init__(self, parent=None):
    7. super(ListWidgetTest, self).__init__(parent)
    8.  
    9. listWidget = QListWidget()
    10. layout = QVBoxLayout()
    11. layout.addWidget(listWidget)
    12. self.setLayout(layout)
    13.  
    14. self.connect(listWidget, SIGNAL("itemDoubleClicked(QListWidgetItem)"), self.printTest)
    15. self.connect(listWidget, SIGNAL("itemClicked(QListWidgetItem)"), self.printTest)
    16. self.connect(listWidget, SIGNAL("itemActivated(QListWidgetItem)"), self.printTest)
    17. item = QListWidgetItem(self.tr("TESTING SIGNALS"))
    18. item.setData(Qt.UserRole, QVariant(1))
    19. listWidget.insertItem(0, item)
    20.  
    21. def printTest(self, item):
    22. print "ok!!"
    23.  
    24.  
    25. if __name__ == "__main__":
    26. import sys
    27. app = QApplication(sys.argv)
    28. dialog = ListWidgetTest()
    29. dialog.show()
    30. app.exec_()
    To copy to clipboard, switch view to plain text mode 

  18. #17
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget SIGNAL Problem

    well i have found the solution, like ever you have reason wysota, the problem was in the connect method. They should be SIGNAL("itemDoubleClicked(QListWidgetItem *)") because of this was not working grrrrr. Many thanks.

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget SIGNAL Problem

    Hmm... in that case connect() should have returned false...

  20. #19
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget SIGNAL Problem

    but returned true, if in c++ it doesnt do should be a PyQt problem, i dont know

  21. #20
    Join Date
    Oct 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidget SIGNAL Problem

    Thanks, helped me with my task

Similar Threads

  1. QLineEdit - lostFocus signal problem
    By Enygma in forum Qt Programming
    Replies: 6
    Last Post: 17th June 2010, 20:52
  2. QListWidget Problem
    By pmabie in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2007, 06:52
  3. QListWidget clicked signal
    By asieriko in forum Qt Programming
    Replies: 12
    Last Post: 10th August 2007, 15:37
  4. Problem emitting signal from a static function
    By Valheru in forum Qt Programming
    Replies: 21
    Last Post: 12th June 2007, 14:48
  5. Replies: 3
    Last Post: 15th April 2007, 19:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.