A bug when show menu and then moving fast the widget?
-
the code is very easy:
1.right click show the menu
2.left click move the widgetmainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui {class MainWindow;} class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); void contextMenuEvent(QContextMenuEvent *); ~MainWindow(); protected: virtual void mousePressEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event); virtual void mouseReleaseEvent(QMouseEvent *event); private: Ui::MainWindow *ui; bool mMoveing; QPoint mMovePosition; }; #endif // MAINWINDOW_Hmainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QtGui/QMouseEvent> #include <QMenu> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); resize(100,100); } void MainWindow::contextMenuEvent(QContextMenuEvent *e) { QMenu *m =new QMenu(this); m->addAction("item1"); m->exec(e->globalPos()); } MainWindow::~MainWindow(){delete ui;} void MainWindow::mousePressEvent(QMouseEvent *event) { mMoveing = true; mMovePosition = event->globalPos() - pos(); return QWidget::mousePressEvent(event); } void MainWindow::mouseMoveEvent(QMouseEvent *event) { if (mMoveing && (event->buttons() && Qt::LeftButton)) { move(event->globalPos()-mMovePosition); mMovePosition = event->globalPos() - pos(); } return QWidget::mouseMoveEvent(event); } void MainWindow::mouseReleaseEvent(QMouseEvent *event) { mMoveing = false; }but, when I show the menu and then moving the widget fast, the widget would not follow the mouse
like this:
however, if no right click, its OK
what problem here is? the problem same show in pyqt too
-
Hi and welcome to devnet,
What version of Qt ?
On what platform ?