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. Add QWidget above QToolBar in QMainWindow
Forum Updated to NodeBB v4.3 + New Features

Add QWidget above QToolBar in QMainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
qmainwindowqtoolbarlayouts
5 Posts 4 Posters 2.5k Views 2 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.
  • R Offline
    R Offline
    Rizwan94
    wrote on 22 Jan 2020, 13:50 last edited by Rizwan94
    #1

    Hello,

    I have a QMainWindow with a central widget, left docked widget and a right docked widget.
    I also have a toolbar at the top.

    Below screenshot depicts my current layout structure.
    438f5a48-4e2b-4884-97fe-9a253ea45410-image.png

    I would like to add a widget on top of the toolbar that would contain the user info like name, DOB etc.
    Expected layout is as depicted by the below image
    13180d42-c84a-461f-9dd7-df973030b05e-image.png

    Is there a way to do it??
    I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.
    But it doesn't help.

    Note: Title widget here is not the "window title", i want to have a separate widget on top of toolbar.

    Can anyone give me a heads up on this ? or is this atleast doable?

    J C 2 Replies Last reply 22 Jan 2020, 16:42
    0
    • R Rizwan94
      22 Jan 2020, 13:50

      Hello,

      I have a QMainWindow with a central widget, left docked widget and a right docked widget.
      I also have a toolbar at the top.

      Below screenshot depicts my current layout structure.
      438f5a48-4e2b-4884-97fe-9a253ea45410-image.png

      I would like to add a widget on top of the toolbar that would contain the user info like name, DOB etc.
      Expected layout is as depicted by the below image
      13180d42-c84a-461f-9dd7-df973030b05e-image.png

      Is there a way to do it??
      I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.
      But it doesn't help.

      Note: Title widget here is not the "window title", i want to have a separate widget on top of toolbar.

      Can anyone give me a heads up on this ? or is this atleast doable?

      C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 22 Jan 2020, 18:43 last edited by Chris Kawa
      #3

      @Rizwan94 said:

      I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.

      That's close, but you need one extra step.
      Create a plain QWidget, set a vertical layout on it, add your widget and toolbar to it and then use setMenuWidget() on your main window.

      EDIT: Or you can even make it simpler - just use your title widget directly as the menu bar.

      R 1 Reply Last reply 23 Jan 2020, 07:41
      4
      • R Rizwan94
        22 Jan 2020, 13:50

        Hello,

        I have a QMainWindow with a central widget, left docked widget and a right docked widget.
        I also have a toolbar at the top.

        Below screenshot depicts my current layout structure.
        438f5a48-4e2b-4884-97fe-9a253ea45410-image.png

        I would like to add a widget on top of the toolbar that would contain the user info like name, DOB etc.
        Expected layout is as depicted by the below image
        13180d42-c84a-461f-9dd7-df973030b05e-image.png

        Is there a way to do it??
        I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.
        But it doesn't help.

        Note: Title widget here is not the "window title", i want to have a separate widget on top of toolbar.

        Can anyone give me a heads up on this ? or is this atleast doable?

        J Offline
        J Offline
        JonB
        wrote on 22 Jan 2020, 16:42 last edited by JonB
        #2

        @Rizwan94
        Before someone else comes up with some clever way to achieve it....

        A QMainWindow has its layout as per https://doc.qt.io/qt-5/qmainwindow.html#details picture, and I don't see it offering you to change that framework. So using a QMainWindow feels like a square peg & a round hole. Are you tied to QMainWindow. If it's your own code and not tied, I'd have a QWidget with the furniture bits added to it. Like I say, until someone says yours can be done with a one-liner on QMainWindow.

        Another possibility is to try inherited QWidget::setLayout() on a QMainWindow. Find out how they've laid it out, and insert your extra title widget before the toolbar ( how did you do your "added that layout above central widget"?). But don't blame me if it doesn't work or makes something go wrong!

        1 Reply Last reply
        0
        • R Rizwan94
          22 Jan 2020, 13:50

          Hello,

          I have a QMainWindow with a central widget, left docked widget and a right docked widget.
          I also have a toolbar at the top.

          Below screenshot depicts my current layout structure.
          438f5a48-4e2b-4884-97fe-9a253ea45410-image.png

          I would like to add a widget on top of the toolbar that would contain the user info like name, DOB etc.
          Expected layout is as depicted by the below image
          13180d42-c84a-461f-9dd7-df973030b05e-image.png

          Is there a way to do it??
          I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.
          But it doesn't help.

          Note: Title widget here is not the "window title", i want to have a separate widget on top of toolbar.

          Can anyone give me a heads up on this ? or is this atleast doable?

          C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 22 Jan 2020, 18:43 last edited by Chris Kawa
          #3

          @Rizwan94 said:

          I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.

          That's close, but you need one extra step.
          Create a plain QWidget, set a vertical layout on it, add your widget and toolbar to it and then use setMenuWidget() on your main window.

          EDIT: Or you can even make it simpler - just use your title widget directly as the menu bar.

          R 1 Reply Last reply 23 Jan 2020, 07:41
          4
          • C Chris Kawa
            22 Jan 2020, 18:43

            @Rizwan94 said:

            I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.

            That's close, but you need one extra step.
            Create a plain QWidget, set a vertical layout on it, add your widget and toolbar to it and then use setMenuWidget() on your main window.

            EDIT: Or you can even make it simpler - just use your title widget directly as the menu bar.

            R Offline
            R Offline
            Rizwan94
            wrote on 23 Jan 2020, 07:41 last edited by
            #4

            Thanks @Chris-Kawa
            Works like a charm!!

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JulienMaille
              wrote on 7 Oct 2020, 18:01 last edited by JulienMaille 10 Jul 2020, 18:04
              #5

              @Rizwan94 May I ask what was your final implementation? I'm trying to setup a frameless window and add my title/close buttons on top of an existing QMainWindow (from .ui)
              Thanks in advance

              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