您的位置:首页 > 编程语言 > Qt开发

QtWidget: 鼠标拖动窗口(没有标题栏时)

2010-05-17 14:21 549 查看
void ShapedClock::mousePressEvent(QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}
void ShapedClock::mouseMoveEvent(QMouseEvent *event) {
if (event->buttons() & Qt::LeftButton) {
move(event->globalPos() - dragPosition);
event->accept();
}
}

const QPoint & QMouseEvent::globalPos () const
Returns the global position of the mouse cursor at the time of the event. This is important on asynchronous window systems like X11. Whenever you move your widgets around in response to mouse events, globalPos() may differ a lot from the current pointer position QCursor::pos(), and from QWidget::mapToGlobal(pos()).

QPoint QWidget::mapToGlobal ( const QPoint & pos ) const
Translates the widget coordinate pos to global screen coordinates. For example, mapToGlobal(QPoint(0,0)) would give the global coordinates of the top-left pixel of the widget.

QPoint QWidget::mapFromGlobal ( const QPoint & pos ) const
Translates the global screen coordinate pos to widget coordinates.

from: http://www.cppblog.com/biao/archive/2009/05/24/85627.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: