@markleo said in are there only five kinds of layouts in Qt?:
Or are there only five kinds of layouts in Qt?
Yes and no.
In most cases these are the base layouts used. However there are also custom layouts with "special" behavior, like
FlowLayout from the Flow Layout Example.
That being said, you can combine the basic layout or build your own layout, if you really need something different (what you cannot reproduce using the five above).
Don't use anchors for the dot, use a fixed value, something like
Image {
id: dot
width: someWidth
height: someHeight
x: someXPositionRelativeToXBodyImage
y: someYPositionRelativeToYBodyImage
.....
}
@mpergand Thanks - this is what I've done but it's not ideal as there two boxes have different "natural" widths as it were, and forcing a proportional size on them is a bit of a kludge. Better than not - but you'd like to think it it shouldn't be needed.
@Axel-Spoerl said in QWidget Drag And Drop inside Layout. Is this a good way?:
I have troubles to imagine what you mean by that. Colors aside, a widget is typically a rectangle. If I want to indicate a potential landing spot, I'd rather use a rectangle, than a line.
I think @StudentScripter means the same behavior you see when adding widgets to a layout in QtDesigner.
A "line" can be a thin rectangle :)
You also see a rectangle when dragging QDockWidgets around showing the valid DockAreas.
Maybe check the source code of QtCreator's Designer or QMainWindows dockarea.
@StudentScripter
You can put pointers to widgets into arrays/lists/maps as you please and use those for iterating through them etc.
You can't get Designer to do that for you, so you have to manually populate the arrays/lists from the ui->... instance variables yourself (after setupUi()).
You can also visit all widgets of a given type, without setting anything up, via topWidget->findChildren<QLineEdit *>().
You can "group" widgets at design-time by e.g. creating a "holding" container QWidget or QFrame or QGroupBox if that helps. For buttons there is also QButtonGroup.
@ChrisW67 Thanks for replying. I was doing as you suggested but still getting the behaviour I specified. Turns out I had a conflicting ui generated header file that had the manually added layout which explains why I was experiencing a NULL layout. Once I deleted the conflicting file everything worked as expected.
Thanks for the extremely easy to follow instructions.
Kevin
@JonB
You have (for unknown reason) placed a button at row #5 column #6 and spanning 5 rows and 2 columns. It's not going to make much sense, is perhaps not what you intend, and will move around when you place other widgets on the grid layout.
I know nothing about "In the gray square there should have been a cube. that I opened",
The second shot shows about what I expect when you didn't use any layout. If the 3 lines of text there were deliberate you would need to put them into the layout now if you expect to see them.
@leonardoMB said in Why Layout is reparenting to the top most widget through addChildLayout?:
What will make _qButton child of widget_1. Where did I go wrong? printing it I have that all are child of widget_1
What will make _qButton child of widget_1?
_qButton = new QPushButton( widget_1 ) or _qButton->setParent( widget_1 ); will make _qButton the child of widget_1.
The layouts of widget_1 can have children of other widgets.
Ok, how about this - Anybody know a way I can add code or set env to enable rotation, (portrait/landscape, or...). As it is, the qt apps don't respond to phone sensors, but are fixes...
Great !
Since you have it working now, please mark the thread as solved using the "Topic Tools" button or the three dotted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)
Thank you for the answer.
Setting a child did enable the layout selection. I don't understand the logic behind that at all but ok.
QcmEntryGuess are QWidget I've created on the side. They're only a QLabel nested in two layout [image: 2e20a2c9-89a4-47e1-a1d3-6234e04464a2.png]
Althought my QGridLayout is still only consisted of one row. I'm probably missunderstanding one of its property
[image: 01294749-1d2a-4443-8237-3744be177d6c.png]