I created myself simple window for debugging purposes. It's completely separate QMainWindow
, so that I can put it on the other monitor when testing the app. But when there's a dialog in my application, I cannot access the window. Right now, this is exactly the time I WANT to access it.
I tried to override QWidget::event
like so:
DebugWindow.h
#include <QtWidgets/QMainWindow>
QT_BEGIN_NAMESPACE
class QEvent;
QT_END_NAMESPACE
class DebugWindow : public QMainWindow
{
Q_OBJECT
public:
DebugWindow(QWidget *parent = 0);
virtual ~DebugWindow();
protected:
virtual bool event(QEvent*);
};
DebugWindow.cpp
bool TechadminScript::event(QEvent* e)
{
if (e->type() == QEvent::WindowBlocked) {
// accept the event to stop propagation
e->accept();
return true;
}
return false;
}
I have set up breakpoint in the overriden function and it was hit - that means I did something right. But the window is still blocked as it was before.
So I am probably missing something, can somebody help me finish this?
It worked for me setting the window modality as @king_nak suggested. Mind you have to hide()
beforehand and show()
according to the documentation: https://doc.qt.io/qt-5/qwidget.html#windowModality-prop
bool Object::eventFilter(QObject *, QEvent * const event)
{
if (event->type() != QEvent::WindowBlocked)
return false;
for (auto&& widget : qApp->topLevelWidgets())
{
if (!widget->isModal())
continue;
widget->hide();
widget->setWindowModality(Qt::NonModal);
widget->show();
}
return true;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.