views:

270

answers:

1

I'm developing a little app (precisely it's a KDE4 plasmoid) in PyQt/PyKde.

In my app I have a KListWidget filled with some rows, see this picture:

I need to implement a drag&drop action for the list rows, for example I should be able to put any file over a row, then the app will send this file to the name on the list.

The list has been created by this snippet of code:

self.contactsList = KListWidget()
self.contactsList.setFrameShape(QFrame.StyledPanel)
self.contactsList.setFrameShadow(QFrame.Sunken)
self.contactsList.setIconSize(QSize(35, 35));

Method to call when drag&drop happens is already implemented, I need only to connect the method to the list in a way similar to:

self.connect(self.contactsList, SIGNAL("signal_()"), self.method)

Any help will be appreciated

A: 

PyQt signals can be defined dynamically, so as long as the class that defines self.contacts_list_method() inherits from QWidget, it can emit a dynamic signal.

For example, at the end of the method in the contactsList object that handles your list appending code:

def contacts_list_method(self, someparameters):
  doStuff()
  doMoreStuff()
  ...
  self.emit(QtCore.SIGNAL("contacts_list_method_done()"))

Then in the initializer of the class that holds the contactsList object (or wherever you feel is a better place) put the following connection:

self.connect(self.contactsList, SIGNAL("contacts_list_method_done()"), self.method)

You could also predefine the QtCore.SIGNAL("contacts_list_method_done()") as an object and then just refer to the object when you emit it in contacts_list_method.

Chris Cameron
this way does not work, but I've solved using a qtreewidget instead of the klistw
Giancarlo
You should post what you actually did as an answer and select it as the correct answer (unless it's company confidential code obviously) so everyone can benefit. I imagine many people will want the behaviour you described at some point :)
Chris Cameron