are there only five kinds of layouts in Qt?
-
The Qt layouts we often see are as follows: There are five kinds (all inherited from QLayout).
QHBoxLayout QVBoxLayout QGridLayout QFormLayout QStackedLayout
However, I have seen other names related to Layout in the official documentation.
For example:QPageLayout QTextLayout
and so on.
Are these used for layout? Or are there only five kinds of layouts in Qt?
-
@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). -
@markleo said in are there only five kinds of layouts in Qt?:
Are these used for layout?
You already mentioned the documentation so:
https://doc.qt.io/qt-6/qpagelayout.html#details
https://doc.qt.io/qt-6/qtextlayout.html#detailsOr are there only five kinds of layouts in Qt?
What are you missing?
-
@markleo said in are there only five kinds of layouts in Qt?:
Are these used for layout?
To see whether any class you are examining can be used for GUI layout (such as placing buttons and other things on a window), you should check whether it:
- Inherits: QLayout
QWidget::setLayout
only accepts pointers to objects that are a (sub-) type ofQLayout
. (Per docs for QWidget.)QPageLayout is not a subtype of QLayout. You can investigate the others as needed. If it isn't a subtype of QLayout, you will not be able to compile code that attempts to pass it to
setLayout
.We could make subjective arguments and counter-arguments about whether the similarity in naming is "confusing" or not. (I offer no opinion on that.)
However, the compiler will ultimately tell you exactly what qualifies as a valid QLayout pointer. So when it comes time to compile the code, any such confusion should very quickly be illuminated.
-
@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). -