0

I am trying to model a UI from a wxWidgets application to QT. However, in the original application they have Dock Widgets that can snap in place and move around except for occupying the main window.

Example UI

Every box appears to be a dock widget except for the main window. And if I want to move the Datasets window (top left) to the right of the Output Adjustment window I can:

Example UI II

So now my goal was to try and get the UI in QT to at least accomplish the dock widgets on the left side of the main widget. Which in my case, I was able to at least get the width and the height with some trouble to show up the same. However, I cannot create a QDockWidget like the Output Adjustment and have it snap next to the others. And the other problem comes when I try to move a dock widget it will not snap to the right or the left of the other widgets.

My UI

This is where I have my problems. I cannot snap it to either side of the dock widgets. Is this something that will need to be hard coded? I know I have seen other examples online that look awfully similar to this layout. However they are all hard coded. And it would be a lot more simple if I could just use the creator to add the sliders and toolbars as time goes on. And if it is not something I have to hard code, how do I modify the locations on where my widgets can snap? I tried to make a grid layout, however the widgets do not go into the grid.

Sailanarmo
  • 1,139
  • 15
  • 41

1 Answers1

1

By enabling dock nesting in your main window you can achieve a more flexible placement of the dock widgets, including positioning the dock widgets side-by-side. In Qt Designer, select the main window and in the Property Editor panel mark the dockNestingEnabled check box (present in the QMainWindow section). Alternatively, you can achieve the same result by calling the method QMainWindow::setDockNestingEnabled in your code.

If you want your application to start with dock widgets arranged side-by-side as in your reference application, you have to resort on the method QMainWindow::splitDockWidget. For example, you can create an initial arrangement in Qt Designer such as the one depicted below.

enter image description here

Next, you can rearrange the dock widgets in the main window constructor code,

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
  ui->setupUi(this);

  // Changes the dock widgets arrangement.
  splitDockWidget(ui->dock1, ui->dock3, Qt::Orientation::Horizontal);
  splitDockWidget(ui->dock1, ui->dock2, Qt::Orientation::Vertical);
}

which would produce the result below.

enter image description here

  • Thank you for your response, I have no idea why I was not notified by this. This solves one of my issues, but the other issue I have still remains where I do not know how to replicated the Output Adjustment bar within the creator itself. Is there not other way to do that other than to hard code it? – Sailanarmo Mar 07 '19 at 18:36
  • @Sailanarmo, I am afraid I did not understand what you mean by "to replicate the Output Adjustment bar." Would it be "adding [sliders](https://en.wikipedia.org/wiki/Slider_(computing)) into the Output Adjustment dock widget"? – Saulo A. Pessoa Mar 08 '19 at 00:42
  • No, apologies for the confusion. Rather, by default, how to I replicate the position of the Output Adjustment dock widget? I can replicate the left 3 docket widget's in the designer, but I do not know how, in the designer, to replicate the position of the Output Adjustment dock widget. – Sailanarmo Mar 08 '19 at 00:46
  • I am not aware of any way to replicate this positioning in the Qt Designer. To the best of my knowledge, it is only achievable by calling the method `QMainWindow::splitDockWidget` in your code. – Saulo A. Pessoa Mar 08 '19 at 02:21
  • Would I call it on the top left dock widget? – Sailanarmo Mar 08 '19 at 02:25
  • I have just updated the answer with a minimalist example of the `QMainWindow::splitDockWidget` usage. – Saulo A. Pessoa Mar 08 '19 at 12:03
  • Thank you for being so helpful. – Sailanarmo Mar 08 '19 at 15:06