我正在尝试实现无框窗口。我在窗口类中编写了一些函数来处理拖放鼠标事件。但是,当我拖动菜单时,我的窗口类没有收到鼠标事件。如何将鼠标事件传播到窗口类?
.h文件:
class MyWindow : public QMainWindow
{
Q_OBJECT
public:
MyWindow(QWidget *parent = 0);
~MyWindow();
private:
Ui::DeblurSoftwareWinClass ui;
protected:
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
QPoint window_drag_start_pos;
};
.cpp文件:
MyWindow::MyWindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
MyWindow::~MyWindow()
{}
void MyWindow::mousePressEvent(QMouseEvent *e) {
if (!isMaximized() &&
e->button() == Qt::LeftButton) {
window_drag_start_pos = e->pos();
}
}
void MyWindow::mouseReleaseEvent(QMouseEvent *e) {
window_drag_start_pos = QPoint(0, 0);
}
void MyWindow::mouseMoveEvent(QMouseEvent *e) {
if (!window_drag_start_pos.isNull()) {
move(pos() + e->pos() - window_drag_start_pos);
}
}
创建项目时默认创建QMenuBar
对象。