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. Sticking multiple windows to each other
Forum Updated to NodeBB v4.3 + New Features

Sticking multiple windows to each other

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.8k Views 3 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.
  • A Offline
    A Offline
    Alex Sivris
    wrote on last edited by
    #1

    Hello!
    I'm currently writing an application on Qt4 that creates multiple small windows and one large window. What can I do to make the small windows "stick" to the sides of the large one? I tried setting the position with QMoveEvent, but then the windows are kind of aligned one over the other, I need them to look like they are on the same level.

    1 Reply Last reply
    1
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Hi and welcome to devnet

      You could have a look to QBoxLayout . Just as a first thought, I would use a hoirzontal layout with a large widget on the left. In the second (right) position there would be vertical layout in which you place all the other widgets.

      You can start with designer and place widgets as you like. This may help you to write it as program or possibly the output of designer is already what you need.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alex Sivris
        wrote on last edited by
        #3

        Thanks for the fast reply!
        The small windows are actually outside of the main window (and each window inherits the QWidget class). I don't understand how I could apply QBoxLayout in this case.

        To give you a better understanding I create the instances
        ps = new Server; <-- small side window
        pc = new Client; <-- small side window
        pgf = new GameField; <-- main window
        (ps,pc and pgf are all pointers to the three classes) and in the constructor of each instance there is a method setupUi, which I guess writes all the content of each class into new windows. I want the borders of these generated windows to stick to the left and right side of the main window (GameField), kind of like in WinAmp (http://www.zeropaid.com/wp-content/uploads/software/81/winamp_main.png)

        K 1 Reply Last reply
        0
        • A Alex Sivris

          Thanks for the fast reply!
          The small windows are actually outside of the main window (and each window inherits the QWidget class). I don't understand how I could apply QBoxLayout in this case.

          To give you a better understanding I create the instances
          ps = new Server; <-- small side window
          pc = new Client; <-- small side window
          pgf = new GameField; <-- main window
          (ps,pc and pgf are all pointers to the three classes) and in the constructor of each instance there is a method setupUi, which I guess writes all the content of each class into new windows. I want the borders of these generated windows to stick to the left and right side of the main window (GameField), kind of like in WinAmp (http://www.zeropaid.com/wp-content/uploads/software/81/winamp_main.png)

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Alex-Sivris
          What I described would be within the main window. Your initial description was scarse in that respect.
          AFAIK you could have just your main window in the beginning and when those addtional information come up you can add this into the QVBoxLayout. It is a way to go, but certainly a matter of taste.
          Another possibility could be QToolBar, but that would be also within the main window.
          Sorry, this is beyond my experience and expertize.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            I wouldn't try to manage this from within moveEvent. This requires a window to know about all other windows and you would end up with a lot of duplicated code in each window class, and then have to implement it every time you add a window. Not that great scaling.

            I would create a separate class to manage this. A sorta external layout if you will. Give it a method to add/remove widgets to track. When adding a widget to track install that class as an event filter and track move events of added widget there. This way you'll have just one place to implement all of it and maintain.

            As for the positioning itself there's no way around it - you will have to track the geometries of the windows and act accordingly.
            I would try to keep two lists: vertical and horizontal edges of the tracked windows. Keep them sorted. When a window moves take it out of the list and on each move find a new place to put it (e.g. with lower bound). If one of the neighboring edges is close enough (within some delta) of the new position adjust that position to "stick".

            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