C++ (Qt)void MyWidget::contextMenuEvent(QContextMenuEvent *e) { e->accept(); MyPopupMenu->exec(mapToGlobal(e->pos()));}
C++ (Qt)MyDialog::MyDialog(QWidget *parent) : QDialog(parent) { ui.setupUi(this); setWindowFlags(Qt::Popup);}
C++ (Qt)void MyWidget::contextMenuEvent(QContextMenuEvent *e) { e->accept(); MyDialogObject->move(e->pos()); MyDialogObject->show();}
void lineEdit::event(QEvent *ev){ if (ev->type() == QEvent::MouseButtonDblClick) { QMessageBox::warning(this, QString::fromLocal8Bit("Бла бла бла"), QString::fromLocal8Bit("бла бла бла"), QMessageBox::Cancel); }}
protected: bool eventFilter(QObject *obj, QEvent *ev);
ui->centralWidget->installEventFilter(this);
bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (obj == ui->centralWidget) { if (event->type() == QEvent::MouseButtonPress) { //QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); //qDebug() << "Ate key press" << keyEvent->key(); ui->listWidget->hide(); return true; } else { return false; } } else { // pass the event on to the parent class return QMainWindow::eventFilter(obj, event); } }