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
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
相关文章推荐
- QtWidget: 鼠标拖动窗口(没有标题栏时)
- QtWidget: 鼠标拖动窗口(没有标题栏时)
- QtWidget: 鼠标拖动窗口(没有标题栏时)
- Qt 左键拖动窗口(没有标题栏)
- QT 隐藏标题栏 窗口移动 鼠标事件
- Qt 背景透明、无边框标题栏、鼠标拖动、定时器、获取屏幕分辨率,设置初始位置
- Qt——鼠标拖动调整窗口大小
- Qt里鼠标拖动窗口的实现
- 鼠标拖动窗口和拉伸(没有标题栏时)
- Qt 背景透明、无边框标题栏、鼠标拖动、定时器、获取屏幕分辨率,设置初始位置
- Qt中,当QDockWidget的父窗口是一个不可以拖动的QTabWidget的时候实现拖动的方法
- QT实现拖拽TabWidget选项卡形成单独的窗口,双击标题栏可还原的功能【dock功能】
- Qt之去除窗口的标题栏、通过鼠标移动窗口
- QT 鼠标拖动无标题窗口
- c# 实现用鼠标拖动没有标题栏的窗口(窗体的任何部分都可实现拖动效果)
- Qt:支持鼠标拖动来移动内容的窗口
- 鼠标单击窗口标题栏,不能拖动窗口
- Java程序中取消窗口标题栏以及边框,并使窗口可以相应鼠标事件,被鼠标拖动;设置JFrame背景色
- Qt::WindowFlags枚举类型(Qt::Widget是独立窗口和子窗口两用的,Qt::Window会有标题栏)
- C#窗体隐藏标题栏后,鼠标可拖动窗口的代码!