Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:00:10+00:00 2026-06-17T19:00:10+00:00

I’m attempting to get my code to work with multiple listViews instead of just

  • 0

I’m attempting to get my code to work with multiple listViews instead of just one but am having an issue.

Working Code for one list:

Class Ui_MainWindow(QtGui.QMainWindow):
    def itemDropped(self, links):
        item = QtGui.QListWidgetItem(url, self.listView)
    def setupUi(self, MainWindow):
        self.connect(self.listView, QtCore.SIGNAL("dropped"), self.itemDropped)  

Class TestListView(QtGui.QListWidget):
    def dropEvent(self, event):
        self.emit(QtCore.SIGNAL("dropped"), links)

What I have so far to use multiple lists:

Class Ui_MainWindow(QtGui.QMainWindow):
    def itemDropped(self, links, listName):
        item = QtGui.QListWidgetItem(url, listName)
    def setupUi(self, MainWindow):
        self.connect(self.listView, QtCore.SIGNAL("dropped"), self.itemDropped(self.listView))  

Class TestListView(QtGui.QListWidget):
    def dropEvent(self, event):
        self.emit(QtCore.SIGNAL("dropped"), links)

So I get an error with “self.itemDropped(self.listView)” and after research on here and other sites I came up with this:

self.connect(self.listView, QtCore.SIGNAL("dropped"),(lambda : self.itemDropped(self.listView)))

I had never used the lambda function before because I am quite new to python but that did fix the issue, when i print listName it shows up correctly. The problem now is that the links aren’t emitting correctly from the other class, or rather I’m not receiving them correctly.

So I guess pseduocode i need something like this:

self.connect(self.listView, QtCore.SIGNAL("dropped"),(lambda : self.itemDropped(X, self.listView)))

The question is how do I get X, that is the links from the TestListView class? I don’t quite understand how I was receiving them with just 1 list when there were no variables being passed to the function.

Thanks for any help you guys can provide i greatly appreciate it.
P.s. Code from here might look familiar if you want a bigger picture PyQT4: Drag and drop files into QListWidget

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:00:13+00:00Added an answer on June 17, 2026 at 7:00 pm

    What you want is this

    self.connect(self.listView, QtCore.SIGNAL("dropped"),(lambda X: self.itemDropped(X, self.listView)))
    

    When you emit your signal, you are passing the links variable into the slot, which used to be self.itemDropped (The signature of which was self.itemDropped (links)).

    Instead you slot is now a lambda function, and so you need to define it as a function of 1 variable by starting the definition with lambda X:. This then makes X available to the rest of the lambda definition.

    When your signal is emitted, your lambda function is called and X contains links.

    In general:
    def foo(x):
    do_something(x)
    foo(3)

    is equivalent to
    my_function = lambda x: do_something(x)
    my_function(3)

    Make sense?

    EDIT: I should also point out (for any future applications you have) that there are some tricky points when using variables inside lambda functions (specifically the use of variables that are not specified in the definition of the lambda function, such as the use of self.listView). When the lambda function is called (when the signal is emitted), it will use whatever the current value of self.listView is, not the value it was when the function was defined. This becomes a problem when defining lambda functions inside a loop and trying to use a loop variable inside your lambda function. Some useful information can be found here (read the comments too) http://eli.thegreenplace.net/2011/04/25/passing-extra-arguments-to-pyqt-slot/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.