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:
{
if( o
== this
->table
->viewport
() && e
->type
() == QEvent::Drop ) {
// do what you would do in the slot
qDebug() << "drop!";
}
return false;
}
bool MainWindow::eventFilter( QObject* o, QEvent* e )
{
if( o == this->table->viewport() && e->type() == QEvent::Drop )
{
// do what you would do in the slot
qDebug() << "drop!";
}
return false;
}
To copy to clipboard, switch view to plain text mode
10 lines of code is all you need.
In case you don't know how to install even filter here's how:
MainWindow
::MainWindow( QWidget* p
) :
{
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 );
}
MainWindow::MainWindow( QWidget* p )
:
QMainWindow( p ),
table( new QTableWidget() )
{
this->table->setColumnCount( 10 );
this->table->setRowCount( 10 );
this->table->setDragEnabled( true );
this->table->setDragDropMode( QAbstractItemView::DragDrop );
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