Qt 通过鼠标移动窗口
生活随笔
收集整理的這篇文章主要介紹了
Qt 通过鼠标移动窗口
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前言
用 Qt 開發(fā)桌面端程序的時(shí)候,通常會(huì)去掉自帶的標(biāo)題欄,然后自定義一個(gè)標(biāo)題欄,那么就需要實(shí)現(xiàn)通過鼠標(biāo)來(lái)移動(dòng)窗體。實(shí)現(xiàn)邏輯其實(shí)很簡(jiǎn)單,只需要捕捉到鼠標(biāo)的坐標(biāo)點(diǎn),在 mouseMove 事件中實(shí)現(xiàn)窗體移動(dòng)。
源碼
void ActionWidget::mousePressEvent(QMouseEvent *event) {if(event->button() == Qt::LeftButton){mousePress = true;}//窗口移動(dòng)距離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);} }總結(jié)
以上是生活随笔為你收集整理的Qt 通过鼠标移动窗口的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt 检测第三方软件是否运行、杀死第三方
- 下一篇: QML WebEngineView简单用