Qt 通过鼠标移动窗口
生活随笔
收集整理的這篇文章主要介紹了
Qt 通过鼠标移动窗口
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
用 Qt 開發桌面端程序的時候,通常會去掉自帶的標題欄,然后自定義一個標題欄,那么就需要實現通過鼠標來移動窗體。實現邏輯其實很簡單,只需要捕捉到鼠標的坐標點,在 mouseMove 事件中實現窗體移動。
源碼
void ActionWidget::mousePressEvent(QMouseEvent *event) {if(event->button() == Qt::LeftButton){mousePress = true;}//窗口移動距離movePoint = event->globalPos() - pos(); }void ActionWidget::mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)mousePress = false; }void ActionWidget::mouseMoveEvent(QMouseEvent *event) {if(mousePress){QPoint movePos = event->globalPos();move(movePos - movePoint);} }總結
以上是生活随笔為你收集整理的Qt 通过鼠标移动窗口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt 检测第三方软件是否运行、杀死第三方
- 下一篇: QML WebEngineView简单用