Qt 4: Move window without title bar

后端 未结 2 1575
太阳男子
太阳男子 2020-12-06 03: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

相关标签:
2条回答
  • 2020-12-06 03:40
    if (event->buttons() && Qt::LeftButton) {
    

    this condition is true for every mouse button

    maybe you kept in mind this

    if (event->buttons() & Qt::LeftButton) {
    
    0 讨论(0)
  • 2020-12-06 03:59

    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.

    0 讨论(0)
提交回复
热议问题