Hi!
eventfilter looks to be easier like subclass it
I have tried to use it, but i dont have understand 100% how to use it,
please help me to understand
test.h:
.
.
protected:
.
.
protected:
bool eventFilter( QObject *o, QEvent *e );
To copy to clipboard, switch view to plain text mode
test.cpp:
MainWindow::MainWindow()
{
ui.setupUi(this);
ui.tree->installEventFilter(this);
// connect(ui.tabellen_cb, SIGNAL(currentIndexChanged (int)), this, SLOT(selectTable()));
connect(ui.actionverbinden, SIGNAL(triggered()), this, SLOT(openLoginDialog()));
connect(ui.actionNeu, SIGNAL(triggered()), this, SLOT(insertNewRow()));
connect(ui.
tree,
SIGNAL(itemDoubleClicked
( QTreeWidgetItem*,
int)),
this,
SLOT(selectTable
()));
init();
}
MainWindow::MainWindow()
{
ui.setupUi(this);
ui.tree->installEventFilter(this);
// connect(ui.tabellen_cb, SIGNAL(currentIndexChanged (int)), this, SLOT(selectTable()));
connect(ui.actionverbinden, SIGNAL(triggered()), this, SLOT(openLoginDialog()));
connect(ui.actionNeu, SIGNAL(triggered()), this, SLOT(insertNewRow()));
connect(ui.tree, SIGNAL(itemDoubleClicked( QTreeWidgetItem*, int)), this, SLOT(selectTable()));
init();
}
To copy to clipboard, switch view to plain text mode
{
Q_CHECK_PTR( contextMenu );
contextMenu->addAction( "&datensatz einfügen", this, SLOT(insertNewRow()) );
contextMenu->addAction( "&datensatz löschen", this, SLOT(deleteRow()) );
contextMenu
->exec
( QCursor::pos() );
delete contextMenu;
}
void MainWindow::contextMenuEvent( QContextMenuEvent * )
{
QMenu* contextMenu = new QMenu( this );
Q_CHECK_PTR( contextMenu );
contextMenu->addAction( "&datensatz einfügen", this, SLOT(insertNewRow()) );
contextMenu->addAction( "&datensatz löschen", this, SLOT(deleteRow()) );
contextMenu->exec( QCursor::pos() );
delete contextMenu;
}
To copy to clipboard, switch view to plain text mode
{
if (event
->type
() == QEvent::ContextMenu) {
return true;
}
else
{
return false;
}
}
bool MainWindow::eventFilter( QObject *o, QEvent *e )
{
if (event->type() == QEvent::ContextMenu)
{
return true;
}
else
{
return false;
}
}
To copy to clipboard, switch view to plain text mode
What is missing. Or what is false?
Bookmarks