Qt 4: Move window without title bar

坚强是说给别人听的谎言 提交于 2019-12-17 16:23:18

问题


I have a Qt::Popup flagged window (which does not have a title bar and close etc buttons) and would like to move by dragging\clicking on the non-title bar area....

On Win32, the solution could be WM_NCLBUTTONDOWN but my requirement is crossplatform.


回答1:


Try this to move the window manually:

void PopupWindow::mousePressEvent(QMouseEvent *event){
    mpos = event->pos();
}

void PopupWindow::mouseMoveEvent(QMouseEvent *event){
    if (event->buttons() & Qt::LeftButton) {
        QPoint diff = event->pos() - mpos;
        QPoint newpos = this->pos() + diff;

        this->move(newpos);
    }
}

And declare QPoint mpos somewhere.




回答2:


if (event->buttons() && Qt::LeftButton) {

this condition is true for every mouse button

maybe you kept in mind this

if (event->buttons() & Qt::LeftButton) {


来源:https://stackoverflow.com/questions/5513060/qt-4-move-window-without-title-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!