Hi Guys
Before I go and subclass QTableWidget, does anyone know of a signal or some other way I can be alerted when an item is dropped in a QTableWidget?
Or do I have to subclass it and reimplement QDropEvent?
Thanks
Jeff
Hi Guys
Before I go and subclass QTableWidget, does anyone know of a signal or some other way I can be alerted when an item is dropped in a QTableWidget?
Or do I have to subclass it and reimplement QDropEvent?
Thanks
Jeff
As far as I know there's no such signal but you could install an event filter on the table widget and handle the drop there instead of using a signal.
Just reimplement QWidget::dragEnterEvent( QDragEnterEvent * event ) function.
Couldn't get the event filter working - I'm assuming it has something to do with QTableWidget having its own implementation of QEvent and QDropEvent.
Reimplementing dragEnterEvent was no good to me as I need to know when an item had actually been dropped - a dragEnterEvent fires regardless of whether the item is dropped or not.
As it is I just subclassed QTableWidget and reImplemented QDropEvent with the following code:
Qt Code:
{ emit itemDropped(); event->accept(); }To copy to clipboard, switch view to plain text mode
Hm , what about to emit signal before event is handled by QTableWidget::dropEvent , also don't see a point in "event->accept()". I mean , i think event will be already handled at this point.
Anyway , i've used to to use QWidget for drag/drop implementation...and any signals' emission seem to work just fine.Here is code snippet :
Qt Code:
{ if( event->provides( ApplicationConstants::supportedMIMEdata) ) event->acceptProposedAction(); // make sure that data being droped can be handled. } { // ... emit dataIsDroped(); }To copy to clipboard, switch view to plain text mode
If the drop signal is the only thing you want and will be used in a signgle place then subclassing is an overkill.
Just use event filter like I've mentioned earlier:
10 lines of code is all you need.Qt Code:
{ { // do what you would do in the slot qDebug() << "drop!"; } return false; }To copy to clipboard, switch view to plain text mode
In case you don't know how to install even filter here's how:Qt Code:
: { this->table->setColumnCount( 10 ); this->table->setRowCount( 10 ); this->table->setDragEnabled( true ); this->table->viewport()->installEventFilter( this ); // that's what you need this->setCentralWidget( this->table ); }To copy to clipboard, switch view to plain text mode
Bookmarks