1

I previously developed an application with PyQT4, including a QListWidget, with a right-click-pop-up-window that allowed the user to quickly delete rows from the widget.

This was based on code from Stack Overflow: PyQt: How to get most of QListWidget

Unfortunately, upon upgrading to PYQt5, this functionality is now broken. I get the error: QListWidget object has no attribute 'connect'.

I suspect this is a due to a new implementation in PyQt5, which is quite annoying, although I can't find a simple way to fix this from the new Qt documentation.

Could someone suggest how I might restore my original functionality please?

I'd prefer to not roll back to Qt5 in the interest of future-proofing.

1 Answer 1

3

In PyQt5, PyQt4's old-style signals and slots are not supported.

So, to fix the problem, replace the line

        self.myListWidget.connect(self.myListWidget, QtCore.SIGNAL("customContextMenuRequested(QPoint)" ), self.listItemRightClicked)

with

        self.myListWidget.customContextMenuRequested.connect(self.listItemRightClicked)

and replace the line

        self.connect(menu_item, QtCore.SIGNAL("triggered()"), self.menuItemClicked) 

with

        menu_item.triggered.connect(self.menuItemClicked)
Sign up to request clarification or add additional context in comments.

1 Comment

This works perfectly, and the code is more readable too. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.