逛奔的蜗牛

我不聪明,但我会很努力

   ::  :: 新随笔 ::  ::  :: 管理 ::

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.


posted on 2009-05-24 18:19 逛奔的蜗牛 阅读(4660) 评论(0)  编辑 收藏 引用 所属分类: Qt自定义Widget

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理