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. Cannot seem to make toolbar be vertical
Forum Updated to NodeBB v4.3 + New Features

Cannot seem to make toolbar be vertical

Scheduled Pinned Locked Moved Solved General and Desktop
33 Posts 2 Posters 13.3k 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #1

    I have inherited an app with a toolbar on the main window via:

    # self == QMainWindow
    self.toolbar = self.addToolBar("Main")
    

    This gives a horizontal toolbar across the top. I wish to change it to a vertical toolbar down the left-hand side. I know this can be done because if I make the toolbar draggable I can drag it there, but I wish it to be fixed at left-vertical.

    Mindful of the available overrides available for QMainWindow.addToolBar(), the admonition in http://doc.qt.io/qt-5/qtoolbar.html#orientation-prop of "This function should not be used when the toolbar is managed by QMainWindow. " and having tried to follow https://stackoverflow.com/a/17327905/489865, I have ended up with:

    self.toolbar = QToolBar()
    self.toolbar.setWindowTitle("Main")
    self.toolbar.setOrientation(QtCore.Qt.Vertical)
    self.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolbar)
    

    (and tried everything in-between), yet my toolbar remains steadfastly horizontal at the top....

    (Actions are added to the toolbar after it has been added to the main window, if that makes any difference....)

    What is the necessary code for a toolbar to come out vertically at the left, either before addToolbar() or after it has been added, please?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi
      Can it be a python binding issue ?
      I took your code in ctor.

      
        auto b = new  QToolBar();
        b->setWindowTitle("OTHER");
        b->setOrientation(Qt::Vertical);
        b->addAction(QIcon(), "TEST");
        addToolBar(Qt::LeftToolBarArea, b);
      
      

      alt text

      1 Reply Last reply
      3
      • JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        Yeah, that looks right. But it can't really shouldn't be a Python issue.

        Although I have tried both ways, could you test your moving the addAction to after the addToolbar, and also add a second action, please?

        mrjjM 1 Reply Last reply
        0
        • JonBJ JonB

          Yeah, that looks right. But it can't really shouldn't be a Python issue.

          Although I have tried both ways, could you test your moving the addAction to after the addToolbar, and also add a second action, please?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @JNBarchan
          ofc
          alt text

            auto b = new  QToolBar();
            b->setWindowTitle("OTHER");
            b->setOrientation(Qt::Vertical);
            addToolBar(Qt::LeftToolBarArea, b);
            b->addAction(QIcon(), "TEST");
            b->addAction(QIcon(), "TEST2");
          
          

          Qt 5.9. visual stud. compiler

          JonBJ 1 Reply Last reply
          1
          • mrjjM mrjj

            @JNBarchan
            ofc
            alt text

              auto b = new  QToolBar();
              b->setWindowTitle("OTHER");
              b->setOrientation(Qt::Vertical);
              addToolBar(Qt::LeftToolBarArea, b);
              b->addAction(QIcon(), "TEST");
              b->addAction(QIcon(), "TEST2");
            
            

            Qt 5.9. visual stud. compiler

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @mrjj
            Thanks. Sigh. Dunno then what my issue is.

            Also, if I make my toolbar movable, I can drag the "gripper" to the left, and it looks vertical, but when I release the mouse it "floats" back up to the top & horizontal.....

            I'll investigate more tomorrow, I guess....

            mrjjM 1 Reply Last reply
            1
            • JonBJ JonB

              @mrjj
              Thanks. Sigh. Dunno then what my issue is.

              Also, if I make my toolbar movable, I can drag the "gripper" to the left, and it looks vertical, but when I release the mouse it "floats" back up to the top & horizontal.....

              I'll investigate more tomorrow, I guess....

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @JNBarchan
              No idea, im totally python noob.
              one thing i would check
              i give it
              LeftToolBarArea = 0x1,
              enum Orientation {
              Horizontal = 0x1,
              Vertical = 0x2
              };

              for setOrientation

              Is your value the same ?
              QtCore.Qt.Vertical

              JonBJ 1 Reply Last reply
              0
              • mrjjM mrjj

                @JNBarchan
                No idea, im totally python noob.
                one thing i would check
                i give it
                LeftToolBarArea = 0x1,
                enum Orientation {
                Horizontal = 0x1,
                Vertical = 0x2
                };

                for setOrientation

                Is your value the same ?
                QtCore.Qt.Vertical

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @mrjj
                Thanks. That's OK, I'm a Python/PyQt/Qt noob :) The values for the various enumerations through PyQt are correct.

                A standalone, 20-line (PyQt) program does work correctly for this. So now I start trying to chop stuff out from the 32K-odd-lines application I have inherited to see if I can get it working there. Wish me luck....

                mrjjM 1 Reply Last reply
                0
                • JonBJ JonB

                  @mrjj
                  Thanks. That's OK, I'm a Python/PyQt/Qt noob :) The values for the various enumerations through PyQt are correct.

                  A standalone, 20-line (PyQt) program does work correctly for this. So now I start trying to chop stuff out from the 32K-odd-lines application I have inherited to see if I can get it working there. Wish me luck....

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @JNBarchan
                  Oh, so its related to full app. Well better than in the actual pyQt.
                  alt text

                  JonBJ 2 Replies Last reply
                  0
                  • mrjjM mrjj

                    @JNBarchan
                    Oh, so its related to full app. Well better than in the actual pyQt.
                    alt text

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @mrjj
                    Well I didn't know it had anything to do with app context till I wrote a standalone just now. But it looks like it is....

                    1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @JNBarchan
                      Oh, so its related to full app. Well better than in the actual pyQt.
                      alt text

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by mrjj
                      #10

                      @mrjj said in Cannot seem to make toolbar be vertical:

                      @JNBarchan
                      Oh, so its related to full app. Well better than in the actual pyQt.

                      BTW, when I get an email notification of that reply of yours it includes a very sweet "Snoopy-good-luck-image" ( :) ), but when I view the post here I see nothing. How does that work? :)

                      mrjjM 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @mrjj said in Cannot seem to make toolbar be vertical:

                        @JNBarchan
                        Oh, so its related to full app. Well better than in the actual pyQt.

                        BTW, when I get an email notification of that reply of yours it includes a very sweet "Snoopy-good-luck-image" ( :) ), but when I view the post here I see nothing. How does that work? :)

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #11

                        @JNBarchan

                        That sounds really odd.
                        Maybe browser blocks external images or something?
                        Its normally visible in forum too.

                        Also your reply have the image
                        as you can see here
                        http://imagizer.imageshack.com/img923/8103/gzf3el.png

                        JonBJ 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @JNBarchan

                          That sounds really odd.
                          Maybe browser blocks external images or something?
                          Its normally visible in forum too.

                          Also your reply have the image
                          as you can see here
                          http://imagizer.imageshack.com/img923/8103/gzf3el.png

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @mrjj
                          Well that too is odd, because I don't see the image under default Firefox from Linux nor IE 11 from Windows.... I do see it under Chrome for Windows... I wonder what the setting is? OTOH, I do see your two "MainWindow" screenshots in all, however...

                          mrjjM 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @mrjj
                            Well that too is odd, because I don't see the image under default Firefox from Linux nor IE 11 from Windows.... I do see it under Chrome for Windows... I wonder what the setting is? OTOH, I do see your two "MainWindow" screenshots in all, however...

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @JNBarchan

                            Maybe its just with animated gifs ?
                            Do you see this ?
                            alt text

                            JonBJ 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @JNBarchan

                              Maybe its just with animated gifs ?
                              Do you see this ?
                              alt text

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by
                              #14

                              @mrjj
                              Yep! But not Snoopy. Somehow I guess it's the source of the Url...

                              mrjjM 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @mrjj
                                Yep! But not Snoopy. Somehow I guess it's the source of the Url...

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @JNBarchan
                                That would also make sense :)

                                1 Reply Last reply
                                0
                                • JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by JonB
                                  #16

                                  @mrjj
                                  Well, good news, and bad news!

                                  I wonder whether you would be kind enough to investigate behaviour for me? The underlying problem seems to be to do with saving & restoring main window state, and is a bit weird....

                                  First, starting from scratch my Python code for vertical, left-hand side toolbar is indeed working fine, in itself, just like the C++ code. So that's good.

                                  The stakeholder has now decided that the toolbar is to be setMovable(True) after all (but still setFloatable(False)).

                                  At this point, I can drag & dock toolbar to all 4 sides fine. As you know, when you drag toolbar main window "expands areas" to visually show where it can be docked, and all 4 are shown.

                                  We save & restore main window layout (see below). If I have dragged toolbar to either left or right vertical all is well, after re-run program and restore toolbar can still be dragged to all 4 positions.

                                  However, if I drag toolbar to either top or bottom horizontal, after re-run program and restore toolbar it is not only possible to drag it to top or bottom, never to left or right, and only the top & bottom areas "expand" to allow drop.

                                  The only way to then rectify this is to delete the saved layout-state .conf file externally. Then all reverts to original good behaviour.

                                  IMPORTANT EDIT:
                                  Skip all following stuff about save/restore, and go straight to next IMPORTANT EDIT afterward.

                                  The code outline is:

                                  1. Take your C++ as starting point.

                                  2. On window close:

                                    QSettings.setValue("main_state", self.saveState())

                                  3. In constructor, after having constructed toolbar & set its options:

                                     mainState = Settings.value("main_state")
                                     if mainState:
                                         self.restoreState(mainState)
                                    

                                  That is what causes this strange behaviour. I'm wondering whether this must somehow to be to do with http://doc.qt.io/qt-5/qtoolbar.html#allowedAreas-prop, because it's as though it's only allowing top & bottom now [EDIT: Just verified self.toolbar.allowedAreas() == Qt::AllToolBarAreas always, both before & after any restores.]; unless it's something to do with the setOrientation not supposed to be used with QMainWindow.... [EDIT: Just removed the setOrientation completely, doesn't seem to be needed (presumably addToolBar(Qt::LeftToolBarArea) is dealing with this for main window, perhaps why they say don't use setOrientation for main window). But no difference for this problem behaviour, so you can try with or without according to me.]

                                  My head hurts. If you fancy looking into this you know I'd be most grateful!

                                  IMPORTANT EDIT:
                                  OK, forget about all the stuff to do with saving/restoring. It's not that. Quite simply, look at the QMainWindow::addToolBar(Qt::LeftToolBarArea, toolbar);:

                                  • If you use Qt::LeftToolBarArea or Qt::RightToolBarArea, you can drag & drop toolbar to all 4 sides.
                                  • But if you use Qt::TopToolBarArea or Qt::BottomToolBarArea, you can never drag & drop to left or right side, only top or bottom.

                                  Period. Given that it can support all 4 drag sides after starting at left or right, yet cannot support drag to left or right if starting at top or bottom, is this a bug??

                                  [EDIT: Oh dear, this only appears to be the behaviour in my app, not in standalone test, I'm investigating further...]

                                  mrjjM 1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @mrjj
                                    Well, good news, and bad news!

                                    I wonder whether you would be kind enough to investigate behaviour for me? The underlying problem seems to be to do with saving & restoring main window state, and is a bit weird....

                                    First, starting from scratch my Python code for vertical, left-hand side toolbar is indeed working fine, in itself, just like the C++ code. So that's good.

                                    The stakeholder has now decided that the toolbar is to be setMovable(True) after all (but still setFloatable(False)).

                                    At this point, I can drag & dock toolbar to all 4 sides fine. As you know, when you drag toolbar main window "expands areas" to visually show where it can be docked, and all 4 are shown.

                                    We save & restore main window layout (see below). If I have dragged toolbar to either left or right vertical all is well, after re-run program and restore toolbar can still be dragged to all 4 positions.

                                    However, if I drag toolbar to either top or bottom horizontal, after re-run program and restore toolbar it is not only possible to drag it to top or bottom, never to left or right, and only the top & bottom areas "expand" to allow drop.

                                    The only way to then rectify this is to delete the saved layout-state .conf file externally. Then all reverts to original good behaviour.

                                    IMPORTANT EDIT:
                                    Skip all following stuff about save/restore, and go straight to next IMPORTANT EDIT afterward.

                                    The code outline is:

                                    1. Take your C++ as starting point.

                                    2. On window close:

                                      QSettings.setValue("main_state", self.saveState())

                                    3. In constructor, after having constructed toolbar & set its options:

                                       mainState = Settings.value("main_state")
                                       if mainState:
                                           self.restoreState(mainState)
                                      

                                    That is what causes this strange behaviour. I'm wondering whether this must somehow to be to do with http://doc.qt.io/qt-5/qtoolbar.html#allowedAreas-prop, because it's as though it's only allowing top & bottom now [EDIT: Just verified self.toolbar.allowedAreas() == Qt::AllToolBarAreas always, both before & after any restores.]; unless it's something to do with the setOrientation not supposed to be used with QMainWindow.... [EDIT: Just removed the setOrientation completely, doesn't seem to be needed (presumably addToolBar(Qt::LeftToolBarArea) is dealing with this for main window, perhaps why they say don't use setOrientation for main window). But no difference for this problem behaviour, so you can try with or without according to me.]

                                    My head hurts. If you fancy looking into this you know I'd be most grateful!

                                    IMPORTANT EDIT:
                                    OK, forget about all the stuff to do with saving/restoring. It's not that. Quite simply, look at the QMainWindow::addToolBar(Qt::LeftToolBarArea, toolbar);:

                                    • If you use Qt::LeftToolBarArea or Qt::RightToolBarArea, you can drag & drop toolbar to all 4 sides.
                                    • But if you use Qt::TopToolBarArea or Qt::BottomToolBarArea, you can never drag & drop to left or right side, only top or bottom.

                                    Period. Given that it can support all 4 drag sides after starting at left or right, yet cannot support drag to left or right if starting at top or bottom, is this a bug??

                                    [EDIT: Oh dear, this only appears to be the behaviour in my app, not in standalone test, I'm investigating further...]

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @JNBarchan

                                    Will do, but first this evening :)

                                    JonBJ 1 Reply Last reply
                                    0
                                    • mrjjM mrjj

                                      @JNBarchan

                                      Will do, but first this evening :)

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by
                                      #18

                                      @mrjj
                                      Cheers, I'll buy you a drink ;)
                                      I did begin to wonder whether you do anything other than answer posts here during working hours... ;-)

                                      mrjjM 1 Reply Last reply
                                      0
                                      • JonBJ JonB

                                        @mrjj
                                        Cheers, I'll buy you a drink ;)
                                        I did begin to wonder whether you do anything other than answer posts here during working hours... ;-)

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        @JNBarchan
                                        oh, i do. ;)
                                        Its just my old pc (2011) is getting tired so with new c++14 and 64bit virtual machines,
                                        it takes a bit to compile and then learning more Qt is always nice.

                                        JonBJ 1 Reply Last reply
                                        0
                                        • mrjjM mrjj

                                          @JNBarchan
                                          oh, i do. ;)
                                          Its just my old pc (2011) is getting tired so with new c++14 and 64bit virtual machines,
                                          it takes a bit to compile and then learning more Qt is always nice.

                                          JonBJ Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on last edited by JonB
                                          #20

                                          @mrjj
                                          If & when you have time to look at my latest edit to my question, you'll see we can skip anything to do with save/restore. The problem seems to be quite simple now: you cannot reposition a toolbar to left/right if it starts at top/bottom, but you can the other way round.....??

                                          [EDIT: Oh dear, oh dear, this is not a problem in the standalone test, only in my actual app. More investigating... :( Any idea at all what might cause this behaviour for me to look at?]

                                          mrjjM 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