Minimum number of Widgets added to a window which have a minimum size
-
I need suggestions about adding a minimum number of widgets to the window.
Widgets should have a minimum size, must not shrink below that size even when more widgets are added to the window layout.For example, suppose by length 10 widgets can get accommodated in row 1, if you add 12 widgets,2 widgets must occupy row 2, and so on.
-
Sound a lot like: https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html
-
Sound a lot like: https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html
@VRonin said in Minimum number of Widgets added to a window which have a minimum size:
Sound a lot like: https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html
In my design, I want to have different widgets of the same minimum size, no matter what the size of the window is, they appear in the same size and when the number of widgets/row increases the widgets will get shifted to the rows below.
-
@VRonin said in Minimum number of Widgets added to a window which have a minimum size:
Sound a lot like: https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html
In my design, I want to have different widgets of the same minimum size, no matter what the size of the window is, they appear in the same size and when the number of widgets/row increases the widgets will get shifted to the rows below.
That is what FlowLayout should do?! Have you tested it already?
-
That is what FlowLayout should do?! Have you tested it already?
Yes, I got its working through the Qt documentation. It's a derived custom layout.
[I have to include all its files in my project to make it work]I wish it were a pre-defined class of Qt. -
Yes, I got its working through the Qt documentation. It's a derived custom layout.
[I have to include all its files in my project to make it work]I wish it were a pre-defined class of Qt.@Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:
I wish it were a pre-defined class of Qt.
If you take the
FlowLayout.cpp
andFlowLayout.h
from the example and create a new class in your project, you can use it, like it has always been there :) -
@Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:
I wish it were a pre-defined class of Qt.
If you take the
FlowLayout.cpp
andFlowLayout.h
from the example and create a new class in your project, you can use it, like it has always been there :)This post is deleted! -
@Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:
I wish it were a pre-defined class of Qt.
If you take the
FlowLayout.cpp
andFlowLayout.h
from the example and create a new class in your project, you can use it, like it has always been there :)If I add
flowlayout.h
inheaders
ofLayout
class andflowlayout.cpp
in the sources ofLayout
class , will it not work? -
If I add
flowlayout.h
inheaders
ofLayout
class andflowlayout.cpp
in the sources ofLayout
class , will it not work?@Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:
will it not work?
Why should it not work?
Why don't you simply try? It is faster than waiting in forum for a response... -
@Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:
will it not work?
Why should it not work?
Why don't you simply try? It is faster than waiting in forum for a response...Yes, I am trying with flowLayout instead of GridLayout, I couldn't see flow Layout working in the way it is expected to work.
-
Yes, I am trying with flowLayout instead of GridLayout, I couldn't see flow Layout working in the way it is expected to work.
@Swati777999 As long as you don't provide more information others can only guess...
- Show your code
- Explain how exactly it misbehaves
-
@Swati777999 As long as you don't provide more information others can only guess...
- Show your code
- Explain how exactly it misbehaves
See the following code.
The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.int n=20; QGridLayout *mSDLayout = new QGridLayout(); QMap <int,QWidget*>dTWidgets; QMap <int, QLabel*>Names; QMap <int ,QTableWidget *> dTs; FlowLayout *flowLayout=new FlowLayout(); // Parent Layout for (int ii=0;ii<n;ii++) { dTWidgets[ii] =new QWidget(); // mSDLayout->addWidget(dTWidgets[ii],0,ii); mSDLayout->addWidget(dTWidgets[ii],0,ii,Qt::AlignCenter); Names[ii] =new QLabel(QString("Name %1").arg(ii+1)); flowLayout->addWidget(Names[ii]); flowLayout->setAlignment(Names[ii],Qt::AlignHCenter); dTs[ii] = new QTableWidget(); flowLayout->addWidget(dTs[ii]); dTWidgets[ii]->setLayout(flowLayout);
This code gives me following result-
-
See the following code.
The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.int n=20; QGridLayout *mSDLayout = new QGridLayout(); QMap <int,QWidget*>dTWidgets; QMap <int, QLabel*>Names; QMap <int ,QTableWidget *> dTs; FlowLayout *flowLayout=new FlowLayout(); // Parent Layout for (int ii=0;ii<n;ii++) { dTWidgets[ii] =new QWidget(); // mSDLayout->addWidget(dTWidgets[ii],0,ii); mSDLayout->addWidget(dTWidgets[ii],0,ii,Qt::AlignCenter); Names[ii] =new QLabel(QString("Name %1").arg(ii+1)); flowLayout->addWidget(Names[ii]); flowLayout->setAlignment(Names[ii],Qt::AlignHCenter); dTs[ii] = new QTableWidget(); flowLayout->addWidget(dTs[ii]); dTWidgets[ii]->setLayout(flowLayout);
This code gives me following result-
@Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:
The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.
- A vector is an array.
- A map is not an array.
dTWidgets[ii]->setLayout(flowLayout);
Tell us:
- Which which should this layout belong to?
- Which widget is your top-level widget?
-
If I add
flowlayout.h
inheaders
ofLayout
class andflowlayout.cpp
in the sources ofLayout
class , will it not work?@Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:
If I add flowlayout.h in headers of Layout class and flowlayout.cpp in the sources of Layout class , will it not work?
Layout
is your project name, not your class.
LayoutExample
is your class name, judging from your header and code file.
What does this file include? Is it the whole FlowLayoutExample or just theFlowLayout
class taken from there? -
@Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:
The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.
- A vector is an array.
- A map is not an array.
dTWidgets[ii]->setLayout(flowLayout);
Tell us:
- Which which should this layout belong to?
- Which widget is your top-level widget?
@JKSH said in Minimum number of Widgets added to a window which have a minimum size:
@Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:
The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.
- A vector is an array.
- A map is not an array.
dTWidgets[ii]->setLayout(flowLayout);
Tell us:
- Which which should this layout belong to?
FlowLayout *flowLayout=new FlowLayout(); // Parent Layout
Flow Layout Example from Qt documentation
I've included flowlayout.h and flowlayout.cpp in theheaders
andsources
ofLayout
project.
- Which widget is your top-level widget?
QWidget *mSWidget = new QWidget(this);
QVBoxLayout *mSLayout=new QVBoxLayout(mSWidget);
mSWidget ->setLayout(mSLayout);
actually it's the outer level box to which an inner level layout is added , now I am focussed on the inner level design which should look like
To FlowLayout ,these units are added as widgets.I hope that I explained it well.