zoukankan      html  css  js  c++  java
  • QtWidget: 鼠标拖动窗口(没有标题栏时)

    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.

  • 相关阅读:
    汇编学习笔记
    英语口语学习
    三层架构与MVC的区别
    “Razor” – a new view engine for ASP.NET
    代码生成
    最热门的敏捷书籍[转]
    推荐工具
    在IBM发现管理的真相[转]
    开源的通用帮助库
    单元测试
  • 原文地址:https://www.cnblogs.com/qq78292959/p/2646267.html
Copyright © 2011-2022 走看看