Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED]How to change toolbar position

    General and Desktop
    4
    10
    9395
    Loading More Posts
    • 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.
    • M
      mbnoimi last edited by

      Hi,

      I want to know how can I change toolbar's position?

      I'm using LTR/RTL layout direction so I've to change toolbar position between right/left.

      1 Reply Last reply Reply Quote 0
      • M
        mbnoimi last edited by

        I tried to use the following but unfortunately it didn't work!

        [code]ui->mainToolBar->move(99, ui->mainToolBar->y());[/code]

        1 Reply Last reply Reply Quote 0
        • E
          Eddy last edited by

          "this wiki could help":http://qt-project.org/faq/answer/how_can_i_make_one_of_my_toolbars_appear_on_the_right_hand_side_of_the_topd

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply Reply Quote 0
          • M
            mbnoimi last edited by

            [quote author="Eddy" date="1396194082"]"this wiki could help":http://qt-project.org/faq/answer/how_can_i_make_one_of_my_toolbars_appear_on_the_right_hand_side_of_the_topd[/quote]

            Unfortunately it didn't help.
            I want to move the shown toolbar from left to right as shown in this screenshot:
            !http://i.imgur.com/CXDDBvt.png(http://i.imgur.com/CXDDBvt.png)!

            1 Reply Last reply Reply Quote 0
            • M
              mbnoimi last edited by

              When I run the following it moves the toolbar but it didn't dock it although I foreced it to be at right!

              [code]ui->mainToolBar->move(this->width()-ui->mainToolBar->width(), ui->mainToolBar->y());
              ui->mainToolBar->setAllowedAreas(Qt::RightToolBarArea);[/code]

              !http://i.imgur.com/JgN6rKs.png(http://i.imgur.com/JgN6rKs.png)!

              BTW, the toolbar back to the left side as soon as I resize the window

              1 Reply Last reply Reply Quote 0
              • Chris Kawa
                Chris Kawa Moderators last edited by

                Don't use move(). This is for widgets not placed in layouts or docks and for windows.
                Also don't set allowed areas like that because the user might want to drag it elsewhere and you're preventing them from doing that.

                To move toolbar left:
                @
                auto toolbar = ui->mainToolBar;
                removeToolBar(toolbar);
                addToolBar(Qt::LeftToolBarArea, toolbar);
                toolbar->show(); //important, because removeToolBar hides it
                @
                To move it right just change the dock area to Qt::RightToolBarArea.

                If you decide to do that you should remember the placement of the toolbars and restore them to that placement on the next app run (eg. via saveState() and restoreState() of QMainWindow) because someone might decided they like it different than what you chose. Don't "force" your users to specific layouts. They usually don't like that.

                1 Reply Last reply Reply Quote 0
                • M
                  mbnoimi last edited by

                  [quote author="Chris Kawa" date="1396203079"]Don't use move(). This is for widgets not placed in layouts or docks and for windows.
                  Also don't set allowed areas like that because the user might want to drag it elsewhere and you're preventing them from doing that.

                  To move toolbar left:
                  @
                  auto toolbar = ui->mainToolBar;
                  removeToolBar(toolbar);
                  addToolBar(Qt::LeftToolBarArea, toolbar);
                  toolbar->show(); //important, because removeToolBar hides it
                  @
                  To move it right just change the dock area to Qt::RightToolBarArea.

                  If you decide to do that you should remember the placement of the toolbars and restore them to that placement on the next app run (eg. via saveState() and restoreState() of QMainWindow) because someone might decided they like it different than what you chose. Don't "force" your users to specific layouts. They usually don't like that.[/quote]

                  Thanks a lot :) This fixed my issue.

                  BTW; How can I use auto datatype? AFAIK it's C++11 feature (I googled about it but I didn't know how to apply it under Qt Creator)

                  1 Reply Last reply Reply Quote 0
                  • M
                    mbnoimi last edited by

                    Do I've always add this in my .pro?

                    [code]QMAKE_CXXFLAGS += -std=c++11[/code]

                    1 Reply Last reply Reply Quote 0
                    • A
                      andreyc last edited by

                      @CONFIG += c++11@

                      1 Reply Last reply Reply Quote 0
                      • Chris Kawa
                        Chris Kawa Moderators last edited by

                        Depends on your compiler. For MSVC this is out of the box depending on its version. For gcc/MinGW you need to add either QMAKE_CXXFLAGS of CONFIG directive in the .pro file as described by you and andreyc. For clang I don't know.

                        auto is not data type. It's type deduction ;) Basically saves you from finger strain. Yeah, C++11 and me is the story of love at first sight. I mean how many times you cursed silently when you had to write something like
                        std::vector<std::pair<std::string, std::map<std::string, int>>>::const_iterator
                        only to be scolded by compiler for not putting space between >>>. Nowadays you just type auto and it's all good :)

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post