user547735
user547735

Reputation:

Drag and Drop in PyQt

I'm new to PyQt and I have a problem, search de google, PyQt docs, Mr. Summerfield's book, but was unable to find a way of sort it.

I have a QListWidget and a QTableWidget all have the drag and drop enable, I use this example: http://zetcode.com/tutorials/pyqt4/dragdrop/

it works fine because the text in the ListWidget goes to the TableWidget and I can further process it, but I need to pick the text immediately after it is drooped in the WidgetList without the need of click in the cell.

Tried:

SIGNAL("itemChanged(QTableWidgetItem*)")
SIGNAL("currentItemChanged(QTableWidgetItem *,QTableWidgetItem *)")

without result.

If any one can help I really appreciate.

Thank you in advance for your cooperation.

Upvotes: 2

Views: 1681

Answers (1)

T Carrasco
T Carrasco

Reputation: 463

I don't quite understand your question, but I'm assuming you want to select, or highlight the item after it's been dropped? Anyhow, this will get you the QTableWidgetItem thats been dropped so you can set focus, select it, etc

If this is the case, you'll want to do it in your drop event.

def dropEvent(self, e)

    # Here's your QTablewidgetItem
    item = self.itemAt(e.pos())

    # Assuming "self" is a QTableWidget, by default will select it as well
    self.setCurrentItem(item)

    # It's also good practice to accept an event you've overwritten

    # Depending on what you're doing, it will be either 
    # QtGui.QTableWidget.dropEvent(self, e)
    # or 
    # e.accept()

Upvotes: 2

Related Questions