Dockable windows / widgets in Qt



  • Hello!

    Dockable widgets in Qt are possible (example). However, usually one can dock a widget in a dockable area of a larger surrounding parent frame. I wonder whether there is a way to attach floating windows with each other, as it is possible in WinAmp (see screenshot).
    Can someone point out whether something like this can be done with Qt?

    !http://i.stack.imgur.com/igajc.png(winamp)!

    What i tried so far: Created a second QMainWindow which overrides the moveEvent(QMoveEvent * event) function and calculate the distance to the parent QMainWindow (line 8). If the second window is near to the parent window, i move it directly next to the parent window (line 13).
    My Problem with this approach: After i moved the second window, the mouse key is still pressed and the window moves back to the position before i automatically moved it.

    My code example right now only works if you try to dock it on the left side of the parent window.
    @void playlistWindow::moveEvent(QMoveEvent * event){
    // Get positions of the two QMainWindows
    QPoint childPosition = event->pos();
    int frameWidth = this->frameGeometry().width() - this->width();
    QPoint parentPosition = this->parentWidget()->pos();

    // Calculate distance to parent Window
    int diffRight = parentPosition.x() - childPosition.x() - this->width() - frameWidth;
    
    // If it is near, move it to the frame of the parent window
    if( diffRight > 5 && diffRight < 30 && !isDocked){
        isDocked = true;
        this->move(childPosition.x() + diffRight, childPosition.y());
    } else {      
        if(diffRight > 30){
            isDocked = false;
        } 
    }
    

    }@
    Is this the right way to do it?

    Thanks for your help,

    Buhmann


  • Moderators

    There is no build-in mechanism in Qt that would do this job for you. I recommend asking/ taking a look at the code of Qmmp player. It's written in Qt and has exactly the same behaviour you describe.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.