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. Stretchable QToolBar
QtWS25 Last Chance

Stretchable QToolBar

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 12.9k Views
  • 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.
  • Y Offline
    Y Offline
    yuriyb
    wrote on last edited by
    #1

    Hi Guys,

    I have created two QToolBar in the top of QMainWindow. Example:

    @ QToolBar * leftToolBar = new QToolBar (this);
    QToolBar * rightToolBar = new QToolBar(this);

    leftToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    rightToolBar->setFixedWidth(150);
    
    leftToolBar->setMovable(false);
    rightToolBar->setMovable(false);
    
    addToolBar(leftToolBar);
    addToolBar(rightToolBar);@
    

    But left tool bar has size according to its contents, and right tool bar stuck to left. Any combination with tool bars policy does not work.

    Is there any way to stretch left tool bar ? May be exists some workaround ? Or it's bug in framework ?

    Thanks in advance.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chernetsov0
      wrote on last edited by
      #2

      Insert widget with QSizePolicy::Expanding into left toolbar using QToolBar::addWidget()

      @
      QWidget *separator = new QWidget(this);
      separator->setSizePolicy(QSizePolicy::Expanding,
      QSizePolicy::Expanding);
      toolBar->addWidget(separator);
      @

      By the way, such convenience method as QToolBar::addStretch() would be nice. I've had this problem myself, some time ago.

      Programmer is an organism that can turn caffeine into code.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yuriyb
        wrote on last edited by
        #3

        [quote author="chernetsov0" date="1312554521"]Insert widget with QSizePolicy::Expanding into left toolbar using QToolBar::addWidget().... I've had this problem myself, some time ago.[/quote]

        I tried this one and I saw this solution before, but in case with two bars on one line it doesn't work.

        Sorry, just forgot... Right bar has 'RightToLeft' layout direction.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chernetsov0
          wrote on last edited by
          #4

          [quote author="yuriyb" date="1312554823"]
          Right bar has 'RightToLeft' layout direction.
          [/quote]

          Why do you use that?

          Programmer is an organism that can turn caffeine into code.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            chernetsov0
            wrote on last edited by
            #5

            If you want some widgets to be in the far right of the toolbar - just join two toolbar into one and insert that separator between actions of the two.

            Programmer is an organism that can turn caffeine into code.

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yuriyb
              wrote on last edited by
              #6

              [quote author="chernetsov0" date="1312555595"]If you want some widgets to be in the far right of the toolbar - just join two toolbar into one and insert that separator between actions of the two.[/quote]

              How I can join two toolbars ?

              I need tool bar like Google Chorme bookmarks bar, where exist place for link buttons and one right button with menu (in chrome 'other bookmarks' tool button).

              1 Reply Last reply
              0
              • C Offline
                C Offline
                chernetsov0
                wrote on last edited by
                #7

                I've tried your solution and buttons on right toolbar seems to be on far right, so what is the problem?

                Programmer is an organism that can turn caffeine into code.

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  yuriyb
                  wrote on last edited by
                  #8

                  Button on far right because 'Right to Left' direction forces tool buttons appear in other order, but I want stretch left bar as far as possible. In my case right tool bar will always contain only one button.

                  Take a look:

                  !http://img36.imageshack.us/img36/339/45775126.png(screen)!

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    chernetsov0
                    wrote on last edited by
                    #9

                    I tried almost everything and still no result.
                    Workaround exists, but requires a lot of extra work.

                    @
                    QToolBar *toolBar = new QToolBar(this);
                    toolBar->setMovable(false);

                    QWidget *separator = new QWidget(this);
                    separator->setSizePolicy(QSizePolicy::Expanding,
                    QSizePolicy::Expanding);

                    toolBar->addAction("Bookmark 1");
                    toolBar->addAction("Bookmark 2");
                    toolBar->addWidget(separator);
                    toolBar->addAction("More Bookmarks");
                    @

                    Dynamically updating tool bar contents will be trickery of another kind (that's the hard part).

                    Programmer is an organism that can turn caffeine into code.

                    1 Reply Last reply
                    0
                    • Y Offline
                      Y Offline
                      yuriyb
                      wrote on last edited by
                      #10

                      Solution with stretcher before button isn't suitable because in case of toolbar overfill, the right button will be invisible. In my application this tool bar filled from item model and handle signals from model to overload.

                      I've tried dirty hack with overload resizeEvent in main window and set fixed width for toolbar dinamically, but behaviour also isn't suitable because in time of resizng main window in some cases hangs.

                      So, do you have any other idea ? As I saw on other forums this problem not just for me.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        chernetsov0
                        wrote on last edited by
                        #11

                        Actually, maybe it's not a bug but rather lack of feature. By default last toolbar get all the toolbar area space. And AFAIK there is no way to change that behavior.
                        If you remove setMovable(false) statements and try to drag that toolbar right, you will see it's possible to do such a thing at the run time.
                        So how about trying not to resize toolbar in resizeEvent implementation but moving it?

                        Programmer is an organism that can turn caffeine into code.

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          chernetsov0
                          wrote on last edited by
                          #12

                          By the way, right-to-left layout has nothing to do with issue.
                          It must, ideally, work without it fine.

                          Programmer is an organism that can turn caffeine into code.

                          1 Reply Last reply
                          0
                          • Y Offline
                            Y Offline
                            yuriyb
                            wrote on last edited by
                            #13

                            I was solve this problem in my app by another way. I removed border in style sheet and handle context menu requests for both tool bar in one point.

                            But would not be bad to see correct handling of QToolBar::sizePolicy by framework in next release.

                            Anyway thanks for your help.

                            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