PDA

View Full Version : default popup of menubar / mainwindow



navid
10th December 2009, 07:55
hi

when you right click on menubar of mainwindow, you see a default popup, shows a checkable list of visible widgets of mainwindow (enable you to show or hide them separately).

there is no contextmenu event code in your code (to access it) and also i didnt find it in qt help.

how can i show the proposed popup(, when click on an item of menubar [NOT right click!])?


regards
navid

aamer4yu
10th December 2009, 11:10
How about using QMainWindow::createPopupMenu (). :rolleyes:

navid
10th December 2009, 14:33
thanks,

is there a way to catch click on menubar items (NOT their subitems / actions)?
i cant find signal for it and prefer not use mouse event handling routine.

navid

navid
10th December 2009, 16:30
it has down with installing event filter for the item of menubar :


bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
static bool _bjust_created = false;
static QMenu * menu;

//menuBar has menuFile, menuView, menuHelp
if(obj != ui->menuView) {
_bjust_created =false;
ui->menuView->clearFocus();
menu->close();
return true;
}
event->accept();
if(!_bjust_created)
if ((event->type() == QEvent::MouseMove)||
(event->type() == QEvent::MouseButtonPress)) {
menu = createPopupMenu ();
menu->exec(ui->menuView->pos());
_bjust_created = true;
}
ui->menuView->clearFocus();
return true;
}

it shows PopupMenu at good position, but after exit of mouse from menuView area,
I have to do a click in other region to disappear the PopupMenu and also
the menuView remain focused and other menuBar items / widgets cant be accessed via mouse.

where is the problem? what is solution?

navid
10th December 2009, 18:29
i found that problem is raised from


MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->menuView->installEventFilter(this);
//does not work: ui->menuView->installEventFilter(parent);
//does not work: ui->menuView->installEventFilter(ui->menuView);
}