Popup and pushButton - how to solve it
-
@TomNow99
Hi
Like
qApp->installEventFilter(filter)
qApp is macro to access the one from main.That should allow you to see the click out side.
BUT
But Before testing that, could you test with grabMouse on dialog ?
it should allow you to get the final click with the code you have.https://doc.qt.io/qt-5/qwidget.html#grabMouse
Make SURE to call releaseMouse()
when you close dialog. always. -
@TomNow99
hi
The "this" is the pointer to the QObject that has the filter func
see here
https://forum.qt.io/topic/83995/eventfilter-anywhere-in-the-program/3
its sets on the QApp. So I guess this for you would be where you have the filterfunction, maybe the dialog or the button.Its grapmouse :) Did you read about it ?
What it does ?
If you tell dialog to grab mouse you cannot click button while dialog is open. but it will work with click outside but that click is used to close dialog and it wont go to button that is outside. -
@mrjj I understand filter. Thank you :)
GrabMouse - I understand fifty - fifty :D
True - I can't click on button. But when I click outside the button ( MainWindow, where I add button ) ) I can't close dialog. When I clicked outside app ( for example click on desktop ) I close dialog.
-
@TomNow99
Ok good :)
well grabmouse simply make all events go to one widget instead of the normal way where they go to widget under mouse
so we say "give me all"Should also work clicking in MainWindow. you should also get that event.
-
@mrjj Now my code looks like:
MainWindow ( where I have button which shows / hides dialog ):
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); button = new QPushButton(this); button->setGeometry(100,100,100,100); connect(button, SIGNAL(clicked()), this, SLOT(clickedSlot())); widget = new tenWidget; // tenWidget is a dialog widget->setFixedSize(300,300); widget->setFocus(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::clickedSlot() { static int click=1; if(click%2==1) { widget->show(); grabMouse(); } else { //widget->hide(); } click++; }
and the dialog ( tenWidget ):
#include "tenwidget.h" tenWidget::tenWidget(QWidget *parent) { setWindowFlag( Qt::FramelessWindowHint); setStyleSheet("QDialog {background-color:red}"); } void tenWidget::focusOutEvent(QFocusEvent *event) { hide(); releaseMouse(); }
Do you think about something like that? Or somewhere I have error?
-
@TomNow99
Hi
I was thinking tenWidget both had grab and release mouse.
As if you let button grab mouse then im not sure you can click on anything in tenWidget.So i would let it grabmouse so it can get the click out side event.
then it can close it. but you cant click on button while its up but clicking over it will close anyway.
its not just really the button :) -
@mrjj I read your post the fourth time and I don't know what I should do next :D
Should I change the place in the code where I grab or release mouse?
EDIT:
Of course I change:grabWindow();
to
widget->grabMouse();
in mainWindow.
But the effect is the same.