I have a dialog that is minimized in its parent window. When I call frameGeometry() the result is active dialog's(not minimized) numbers.
I want to know where the titleBar is. (when dialog minimized just shown titleBar of the dialog)
Can you try this
header file
#ifndef MYDIALOG_H
#define MYDIALOG_H
#include <QtWidgets/QDialog>
#include <QtWidgets/qmainwindow.h>
class MyDialog : public QDialog
{
Q_OBJECT
public:
MyDialog(QWidget *parent = 0);
~MyDialog();
protected:
virtual bool nativeEvent(const QByteArray & eventType, void * message, long * result);
};
class MyWindow : public QMainWindow
{
Q_OBJECT
public:
MyWindow();
~MyWindow();
private:
MyDialog * m_dialog;
};
#endif // MYDIALOG_H
source file
#include "mydialog.h"
#include <windows.h>
#include <windowsx.h>
#include <QDebug>
#include <QTimer>
MyDialog::MyDialog(QWidget *parent)
: QDialog(parent)
{
setStyleSheet("QDialog{background-color: red}");
}
MyDialog::~MyDialog()
{
}
bool MyDialog::nativeEvent(const QByteArray & eventType, void * message, long * result)
{
MSG* msg = (MSG*)(message);
if (msg->message == WM_NCLBUTTONDOWN)
{
if (isMinimized())
{
QTimer::singleShot(50, this, SLOT(showNormal()));
*result = 0;
return true;
}
else
{
int mouseX = GET_X_LPARAM(msg->lParam);
int mouseY = GET_Y_LPARAM(msg->lParam);
QRect frame = frameGeometry();
QRect content = geometry();
qDebug() << "frame: " << frame;
qDebug() << "content: " << content;
if (mouseY < content.y() && mouseY >= frame.y())
{
qDebug() << "Hit title bar";
showMinimized();
}
}
}
*result = 0;
return false;
}
MyWindow::MyWindow()
:QMainWindow()
{
setStyleSheet("QMainWindow{background-color: blue}");
showMaximized();
m_dialog = new MyDialog(this);
m_dialog->showMinimized();
}
MyWindow::~MyWindow()
{
}
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.