Frage

I'm currently doing a map editor for a game I created, and I have a tiny problem with Qt. It's the first time I use it, but I love the challenge and I thought it would be a great experience.

I'm currently building my interface using Qt Designer and I'm stuck on the map part. Indeed, my map is composed of 2 layers : The terrain, and the units/obstacles/vegetation.

I'm using a QTableWidget to contain the terrain information, but now I would like to stack another QTableWidget above it, with the exact same size, so I can place my units, etc. However, I didn't find how to achieve this on Qt Designer. As soon as I create a new QTableWidget, it goes on the side of the first, not above it.

I thought about using the QStackedWidget, but since it only allows 1 Widget to be visible at a time, it doesn't fit my hope.

If someone has an idea, as tiny as it might be, I would be very thanksful.

Have a nice day everyone !

EDIT : By above, I don't mean aside... I know it's kinda hard to explain. If we consider that the Axis on which we look our screen is Z, I would like both tables to be : - Equivalent on the X Axis (same number of columns) - Equivalent on the Y Axis (same number of row) - Different on the Z Axis (one table is "deeper")

War es hilfreich?

Lösung

Note: This answer is off-topic, as I misunderstood the question. The question is about stacking widgets but painting all of them. However, I leave it there if a future reader wants to put widges one below the other. (See the comments on the questions for details.)


You can put widgets one below the other using QVBoxLayout. Just select the two table widgets and select 'Lay out' > 'Lay out vertically' in the context menu. You should then use row stretches to tell the layout that the widgets should have the same sizes. As far as I know, stretches can only be set using C++ code, not from within your .ui designer file. This can be done by putting these two lines in the constructor of your widget class, right after ui->setup(this);:

ui->verticalLayout->setStretch(0, 50); //  50%, but the number doesn't have to be
ui->verticalLayout->setStretch(1, 50); //  in percent, so 1 / 1 is the same.

If I understand it correctly, you want to have a big widget, your map editor's main widget, and the two other widgets below or at the side. If they are below, you can put this together into one QVBoxLayout and set the stretches, for example, to 3:1:1, which makes the main widget occupy 60% of the available height and your two table widgets 20% each:

ui->verticalLayout->setStretch(0, 3);
ui->verticalLayout->setStretch(1, 1);
ui->verticalLayout->setStretch(2, 1);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top