click left mouse button, window's position change
Solved
General and Desktop
-
CustomizeQWidget::CustomizeQWidget(QWidget *parent) : QDialog(parent) { this -> setWindowFlags(Qt::FramelessWindowHint); } CustomizeQWidget::~CustomizeQWidget() { } void CustomizeQWidget::paintEvent(QPaintEvent *) { QStyleOption opt; opt.init(this); QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); } void CustomizeQWidget::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) { m_last_mouse_position = event->globalPos(); } } void CustomizeQWidget::mouseMoveEvent(QMouseEvent *event) { if (!event->buttons().testFlag(Qt::LeftButton)) return; const QPoint position = pos() + event->globalPos() - m_last_mouse_position; //the position of mainfrmae + (current_mouse_position - last_mouse_position) move(position.x(), position.y()); m_last_mouse_position = event->globalPos(); }
I written code like this. it removed system's Frame and can be dragged. But , When I clicking a QPushButton throw mouse left button, keep a little time, the windows's position got changed. How can I fix it.
-
@chris_rookie
I would suggest, by defining an area where you want the mousePressEvent to be a valid starting point.If pressed in that area set a bool/flag to true and only move, when that variable allows it ?