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. [SOLVED]How to change toolbar position
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to change toolbar position

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 10.8k Views 1 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.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #1

    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
    0
    • M Offline
      M Offline
      mbnoimi
      wrote on last edited by
      #2

      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
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #3

        "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
        0
        • M Offline
          M Offline
          mbnoimi
          wrote on last edited by
          #4

          [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
          0
          • M Offline
            M Offline
            mbnoimi
            wrote on last edited by
            #5

            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
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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
              0
              • M Offline
                M Offline
                mbnoimi
                wrote on last edited by
                #7

                [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
                0
                • M Offline
                  M Offline
                  mbnoimi
                  wrote on last edited by
                  #8

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

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

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andreyc
                    wrote on last edited by
                    #9

                    @CONFIG += c++11@

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

                      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
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved