Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dockable windows / widgets in Qt
Forum Updated to NodeBB v4.3 + New Features

Dockable windows / widgets in Qt

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Buhmann
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved