Change the location of the QTabBar holding QDockWidgets? - qt

I have a QMainWindow with several QDockWidgets all in the same area, which forces the dock widgets to be tabbed in a QTabBar. The tabs appear at the bottom left corner of the dock area. (In the screenshot the tabs are named "Properties", "Resources", "Attribute Editor", and "Operations".)
Is is possible change where the tabs are located relative to the dock widgets? Specifically, can the tabs be placed above the dock widgets instead of below them?

Use QMainWindow::setTabPosition() method (Qt documentation).
// Will display the tab above the docked widgets in the left side
mainWindow->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);

Related

How to dock a QDockWidgets inside a QSplitter?

I am trying to have a QSplitter accept QDockWidgets in my application. So far, I have done everything through the Qt Designer and what I have done is create three individual QWidgets. I then select all three of the QWidgets and I right click on them and select Layout->Lay out Vertically in a Splitter.
This lays all three of the widgets in a splitter quite nicely. I then drag a Dock Widget to the Object/Class Window in the top right and set them in the Splitters Widget. This places the QDockWidget happily inside the widget. However, when I fire up the program I cannot click and drag the dock widgets. If I double click the dock widget, the dock widget will pop out, however I cannot place it back since it was never technically docked. Which then creates the problem of the widget not being allowed to dock anywhere else. It cannot be docked on the QMainWindow class or in the QSplitter class.
Is there anyway to have a QDockWidget docked inside of a QSplitter and have the functionality of a QDockWidget?
After you add the dock widget to the QSplitter, the widget has become part of the splitter.
You can try checking like this
//If sure of Dockwidget at zeroth position
QDockWidget *widget1 = (QDockWidget*)ui->splitter->children().at(0);
A Dockwidget has a feature of floating as a top level window.
But you can make a dockwidget look like other widgets by setting QDockWidget::NoDockWidgetFeatures
Either:
Go to the object window in Qtdesigner (top -> right)
And select the dock widget added to splitter.
In proeprties window, down below scroll down and look for "features".
Then uncheck the features like movalble, closable etc....
I made it NoDockWidgetFeatures.
or
You can set programmatically using setFeatures(QDockWidget::NoDockWidgetFeatures)

How can I allow user resize on elements within the window using Qt designer?

I want to allow a user using my application to be able to drag a boundary between two widgets in my window which will resize the two (i.e. you drag it down and the top one will get bigger while the bottom gets smaller, and vice-versa).
Is there anything in Qt designer that will allow a user to resize an element in the window, within certain constraints?
Thank you
What you're describing is called a QSplitter widget. In Qt Designer, you can create one by selecting 2 or more widgets, and then clicking the splitter button on the toolbar at the top. It's in the same location as the layout buttons. It will place those widgets inside a QSplitter. You still need to place the splitter widget inside another layout. It will create a handle between them to let you resize the portion that each widget gets.
You're looking for the QDockWidget. It can do all that you described above and more. The user can dock the widget to different sides of the window, changing which widget is on the top or bottom. You can customize the minimum and maximum sizes, as well as default sizes.

Qt-designer: enlarging the window does not replace my items

To keep the question as simple as possible, I prepared a simple Qt designer form below
There is a Tab Widget on the left side and empty QWidget on the right side, the QWidget as a GroupBox. The Groupbox has a radio and pusbuttons (you can see them on Object inspector window on the photo as well ). The tab widget has a line edit. The central widget has a gridlayout and horizontal qsplitter is used.
My issue is that when I enlarge the window, all items (lineedit, radiobutton, pushbutton) are on the fix position. Here is an example what I mean:
What I want is that when the window is enlarged the items should be placed on the bottom of the window, or if they are in the middle, then they should stay in the middle. ( I don't want size of the buttons/lineedits to be changed).
How can I do it?
The items you want to move dynamically, with window resizing must be in a layout.
So, in the example you've posted, you need two layouts; one inside the tab widget, for the QLineEdit and at least one in the GroupBox for the radio button and push button.
If you want the radio and push button to be aligned horizontally, you can start by placing them in a horizontal layout, before placing that layout in another, which all reside in the group box.
When you start to add items to layouts, such as push buttons, you'll start to notice that they can get stretched, so you may need to set the size policies of the widgets.
If you want the line edit to be centered horizontally, you will have to place two horizontal spacers on each side of the line edit and select the three together and set "Lay out Horizontally". This can found at the top toolbar in Qt Designer.
To always have it at the bottom of the tab widget, put a vertical spacer above the line edit in your tab widget. Then select the option "Lay out vertically" for the tab widget.
The same goes for your radio button and push button. Keep them in a horizontal layout, with horizontal spacers if required and put a vertical spacer into the group box and set the layout property for the group box as "Lay out Vertically".
Most important of all, I suggest you go through some basic tutorials before you continue. Here is a link to a good channel on youtube.
https://www.youtube.com/playlist?list=PL2D1942A4688E9D63
If you don't have a layout in your tabWidget or GroupBox:
You must set a layout (for example QVBoxLayout) inside your tab widget and a group box.
It can be done using QtDesigner. It also can be done in code like this:
QWidget *window = new QWidget;
QPushButton *button1 = new QPushButton("One");
QPushButton *button2 = new QPushButton("Two");
QPushButton *button3 = new QPushButton("Three");
QPushButton *button4 = new QPushButton("Four");
QPushButton *button5 = new QPushButton("Five");
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
layout->addWidget(button4);
layout->addWidget(button5);
window->setLayout(layout);
But if you do, and then you want your buttons to stay at the bottom:
Then you have to try setRowStretch method http://qt-project.org/doc/qt-4.8/qgridlayout.html#setRowStretch or take a look at QSpacerItem.

expanding widgets inside a Qtabwidget

Why does the widgets inside a QTabWidget don't resize?
All my widgets resize except for the ones inside the tabs, even the tabs resize, but not the items inside it.
Is this because of the type of layout as I show in the figure?
I can's assign a layout to it. this is before and after maximizing the window.
Why can't you assign a layout to it? You just have to give each tab a layout. Drag your widget into the tab. Select the tab, not the widget, click on one of the layouts in the top row of the designer. Your widget will fill the whole tab and resize nicely.

QT - sliding widget

I'm new in QT interfaces. I would like to create sliding widget in my desktop application (no QML). Idea is to create sliding menu like facebook component on some web pages.
For example:
I have main window and I want to have small part of widget on the right window edge
When mouse move on this widget (or click on it) then this widget slide to show all its content.
I know how to create animation and handle mouse events. There is a lot of examples about it. The problem is that this menu widget should not interact with other layouts and widgets. I mean, main window has root horizontal layout and I don't know how to exclude this widget from it and place widget in front of all widgets on main window. Are exists some layers in QT?
You could accomplish similar functionality by overlaying a custom QDockWidget. This widget could then float above the other widgets in a fixed position relative to your mainwindow. Connect the main window's resize/move events to slots on your QDockWidget that keeps their positions in sync.

Resources