[SOLVED]How to change toolbar position
-
-
[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)! -
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
-
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 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)
-
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 :)