Solved QToolBar and other QWidgets
-
I'm trying to do something simple but I don't understand how to do.
In aQMainWindow
I have twoQToolBar
: one places in the top side and the other in the left side. Both fill the whole width and height of the window.Instead I need to place some other
QWidget
at the beginning or at the end of the tool bars. Say, in the left-top corner I would place aQImage
to show the logo and hence the tool bars should be placed at the right and bottom side of this widget.Even simpler, I cannot place the tool bar in a
QLayout
(the Designer doesn't allow me to drag and drop them).
Any idea? -
Hi
you mean insert QImage outside the toolbar(s) but in same area where it lives ?While you can insert a toolbar in a layout from code, it would disable Mainwindows normal features
of being able to float them and drag toolbars around. -
@mrjj said in QToolBar and other QWidgets:
you mean insert QImage outside the toolbar(s) but in same area where it lives ?
Exactly. Another example: in my vertical tool bar I only have three big buttons. I would use the space below them to put other stuff, outside the tool bar but in the same "vertical" area, like if they are using a
QVBoxLayout
.While you can insert a toolbar in a layout from code, it would disable Mainwindows normal features
of being able to float them and drag toolbars around.I'm not interested in these features. Because I've already customized my toolbars from the Designer I would like to avoid to re-write all the code in the cpp file.
Could I just "move" them reassigning the parent to a new
QLayout
? -
@Mark81
Well the QToolBar is a normal widget so its possible to use it as such. Like say in a Dialog.
So your idea should not be impossible.-
Because I've already customized my toolbars from the Designer
well we could just take the code from setupUI so it would not have to be rewritten. :) -
Could I just "move" them reassigning the parent to a new QLayout?
Well im not really sure what the QToolbar area really is.
If its a layout of sorts, then reassigning parent might not work as we expect as
for layout TakeAt seems the way to transfer ownership.
But please try it :) It it doesnt work, we should find out via source code or
via findChildren(); and see what we are dealing with.
Update. had a quick looks and it seems to live in a QToolBarLayout
which seems to be a private class. tried to use TakeAt but gave me null ptr. -
-
Following your hints I did that entirely by code.