[Qt-interest] bug with mouse events
Ivan S. Lyapunov
dront78 at gmail.com
Tue Feb 10 17:59:15 CET 2009
Hello.
I'm write a small program and i want to make frameless parent window with
mouse dragging enabled
This code has a bug on Windows XP (and m.b anywhere else)
when system panel with Start menu button is placed on left or on top of the
desktop
qwidget::mouseMoveEvent receives incorrect coordinates, so the dragging
window jump to the width()/heith() of the system Start menu panel.
The manual drag works if Qt::Popup style is enabled to widget but it is not
a correct style for use.
I'm using qt 4.5 rc1, compiled this Visual Studio 2005 SP1
the sample of the problem code is attached
// QMoveError.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QtGui/QDesktopWidget>
#include "QErrWidget.h"
int _tmain(int argc, char* argv[])
{
QApplication app(argc, argv);
QApplication::desktop()->availableGeometry();
QWidget *q = new QErrWidget;
q->show();
return app.exec();
}
// QErrWidget.h
//
#include <QtGui/QWidget>
#ifndef QERRWIDGET_H
#define QERRWIDGET_H
class QErrWidget : public QWidget
{
private:
int _dx, _dy;
bool m_drag;
protected:
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
public:
QErrWidget(void);
virtual ~QErrWidget(void);
};
#endif
// QErrWidget.cpp
#include "QErrWidget.h"
#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QtGui/QDesktopWidget>
#include <QtGui/QMouseEvent>
QErrWidget::QErrWidget(void)
: QWidget(0, Qt::Window | Qt::WindowMinimizeButtonHint |
Qt::WindowSystemMenuHint | Qt::FramelessWindowHint),
_dx(-1), _dy(-1), m_drag(false)
{
resize(320, 240);
move((QApplication::desktop()->size().width() - width()) / 2,
(QApplication::desktop()->size().height() - height()) / 2);
}
QErrWidget::~QErrWidget(void)
{
}
void QErrWidget::mousePressEvent(QMouseEvent *event)
{
// drag window operations here
if (!m_drag && Qt::LeftButton == event->button()) {
_dx = event->x();
_dy = event->y();
m_drag = true;
}
}
void QErrWidget::mouseReleaseEvent(QMouseEvent *event)
{
// drag window operations here
m_drag = false;
}
void QErrWidget::mouseMoveEvent(QMouseEvent *event)
{
// drag window operations here
if (m_drag) {
const int dx = event->x() - _dx;
const int dy = event->y() - _dy;
move(this->x() + dx, this->y() + dy);
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090210/e2e93e49/attachment.html
More information about the Qt-interest-old
mailing list