Pregunta

I want to activate an item from listWidget, that is part of ChildWidget, using event filter in parentWidget. Here is part of the relevant parentWidget code:

    self.w = ChildWidget()
    def eventFilter(self, source, event):
      if event.type() in (QtCore.QEvent.MouseButtonPress,
                        QtCore.QEvent.MouseButtonDblClick):
        if event.button() == QtCore.Qt.LeftButton:
                self.w.listWidget.itemActivated

and in ChildWidget:

    self.listWidget.itemActivated.connect(self.klik)
    if item.data(Qt.UserRole).toPyObject():
        mp3=item.data(Qt.UserRole).toPyObject()
        playsnd("/home/pi/Desktop/komunikator/Recenice/pekara/"+mp3)

The event filter works fine, just the command

self.w.listWidget.itemActivated

isn't working. Is there other way to activate item and trigger item activated signal to be sent?

¿Fue útil?

Solución

In [9]: q.itemActivated
Out[9]: <bound signal itemActivated of QListWidget object at 0x1d13560>

You are not calling it.

But let's try to call it.

In [10]: q.itemActivated()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-3602f33f377a> in <module>()
----> 1 q.itemActivated()

TypeError: native Qt signal is not callable

You can't call it, you must call the bound procedure directly. To emit a signal you must use emit.

q.itemActivated.emit(None)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top