Syntax for Vector of QPushbuttons added to FlowLayout
-
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
I want to set the scrolling functionality for the array of pushbuttons. That's the reason why I put scrollArea inside the flowLayout.
Then you should:
- Put the flowLayout in a container/child widget
- Put that container/child widget in the scrollArea
But before that, simplify your design and remove the widgets and layouts that you don't need. Both myself and @Pl45m4 have asked you to do this. Please don't ignore our words.
Yes, check the revised code as below:
{ QWidget *flowWidget = new QWidget(this); FlowLayout *flowLayout = new FlowLayout(); flowWidget->setLayout(flowLayout); int n=20; QVector <QPushButton *> buttons(n); for (int ii=0;ii<n;ii++) { QPushButton * pb = new QPushButton(); // creating buttons pb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb); } QScrollArea *scroll =new QScrollArea(this); scroll->setWidget(flowWidget); this->show(); }
It gives me following output :
scrollArea inside another window .If I declare
scroll
widget as below:
QScrollArea *scroll =new QScrollArea();
I get a blank window.If I declare
scroll
widget as follows:
QScrollArea *scroll =new QScrollArea(flowWidget);
my program crashes. -
Yes, check the revised code as below:
{ QWidget *flowWidget = new QWidget(this); FlowLayout *flowLayout = new FlowLayout(); flowWidget->setLayout(flowLayout); int n=20; QVector <QPushButton *> buttons(n); for (int ii=0;ii<n;ii++) { QPushButton * pb = new QPushButton(); // creating buttons pb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb); } QScrollArea *scroll =new QScrollArea(this); scroll->setWidget(flowWidget); this->show(); }
It gives me following output :
scrollArea inside another window .If I declare
scroll
widget as below:
QScrollArea *scroll =new QScrollArea();
I get a blank window.If I declare
scroll
widget as follows:
QScrollArea *scroll =new QScrollArea(flowWidget);
my program crashes.@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
Yes, check the revised code as below:
Good! It is much cleaner now.
scrollArea inside another window .
That's because your scrollArea is a child widget but you did not put it inside a layout.
Questions:
- In your latest code, who is scrollArea's parent?
- Do you need scrollArea to be a child widget? In other words, does scrollArea need a parent?
- How would you make scrollArea a top-level widget?
-
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
Yes, check the revised code as below:
Good! It is much cleaner now.
scrollArea inside another window .
That's because your scrollArea is a child widget but you did not put it inside a layout.
Questions:
- In your latest code, who is scrollArea's parent?
- Do you need scrollArea to be a child widget? In other words, does scrollArea need a parent?
- How would you make scrollArea a top-level widget?
@JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:
That's because your scrollArea is a **child widget** but you did not put it inside a **layout.
If I writeflowLayout ->addWidget(scroll);
, my program ends forcefully.Questions:
1. In your latest code, who is scrollArea's parent?
Ans: the mainwindow (I've set its parent to bethis
. As mentioned above, if I set it's parent to be flowWidget,my program crashes.2. Do you need scrollArea to be a child widget? In other words, does scrollArea need a parent?
Ans : It's like the main window is the parent ; its child is flowWidget whose children are buttons , scroll is to be applied to flowWidget such that scroll functionality works for all the buttons simultaneously.Note : I should be able to navigate to the buttons at the bottom from the top buttons by scrolling. This is my objective.
3. How would you make scrollArea a top-level widget?
Ans: It was just a part of my experimentation, as it is not working neither forscroll->setWidget(flowWidget)
nor forQScrollArea *scroll = new QScrollArea (flowWidget);
I hope it makes much sense now/
-
@JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:
That's because your scrollArea is a **child widget** but you did not put it inside a **layout.
If I writeflowLayout ->addWidget(scroll);
, my program ends forcefully.Questions:
1. In your latest code, who is scrollArea's parent?
Ans: the mainwindow (I've set its parent to bethis
. As mentioned above, if I set it's parent to be flowWidget,my program crashes.2. Do you need scrollArea to be a child widget? In other words, does scrollArea need a parent?
Ans : It's like the main window is the parent ; its child is flowWidget whose children are buttons , scroll is to be applied to flowWidget such that scroll functionality works for all the buttons simultaneously.Note : I should be able to navigate to the buttons at the bottom from the top buttons by scrolling. This is my objective.
3. How would you make scrollArea a top-level widget?
Ans: It was just a part of my experimentation, as it is not working neither forscroll->setWidget(flowWidget)
nor forQScrollArea *scroll = new QScrollArea (flowWidget);
I hope it makes much sense now/
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
I hope it makes much sense now
Not really, at least not to me.
For what purpose is the
FlowWidget
now?
Can't you just assign the flowLayout to your mainWindow?Note: scrollArea can handle one entire widget (with all of its sub-widgets and layouts). As far as I understood, your buttons are on multiple widgets, am I right?!
Don't know how your "scroll from top buttons down to bottom buttons" should work. At least when the entire widget is as big as the parent window.Edit:
Quick fix: set your main widget (whatever it might be, maybescrollArea
?!) as centralWidget withsetCentralWidget(.....)
, so the content covers your whole mainWindow. -
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
I hope it makes much sense now
Not really, at least not to me.
For what purpose is the
FlowWidget
now?
Can't you just assign the flowLayout to your mainWindow?Note: scrollArea can handle one entire widget (with all of its sub-widgets and layouts). As far as I understood, your buttons are on multiple widgets, am I right?!
Don't know how your "scroll from top buttons down to bottom buttons" should work. At least when the entire widget is as big as the parent window.Edit:
Quick fix: set your main widget (whatever it might be, maybescrollArea
?!) as centralWidget withsetCentralWidget(.....)
, so the content covers your whole mainWindow.@Pl45m4 said in Syntax for Vector of QPushbuttons added to FlowLayout:
For what purpose is the
FlowWidget
now?Can't you just assign the flowLayout to your mainWindow?
Yes, this is what I did at the first place but I followed the suggestion of @JKSH for implementing the scrollArea for all button widgets.Then you should: Put the flowLayout in a container/child widget Put that container/child widget in the scrollArea
So, I put the entire flowlayout inside a flowWidget.
Note: scrollArea can handle one entire widget (with all of its sub-widgets and layouts). As far as I understood, your buttons are on multiple widgets, am I right?!
Yes, my buttons are arrays of widgets. I want to enable scrolling property just the way I use this link of this forum ; to be able to navigate from top to bottom of this page where the contents of my windows are buttons.Don't know how your "scroll from top buttons down to bottom buttons" should work. At least when the entire widgets is as big as the parent window.
I want to navigate to the bottom of the mainwindow through the scrollbar where the contents of the mainWindow are buttons , just like the following picture; scrollbar in the bottom and right side. In the figure, there are 20 push buttons but I can only view 12 out of them in my window.
-
@Pl45m4 said in Syntax for Vector of QPushbuttons added to FlowLayout:
For what purpose is the
FlowWidget
now?Can't you just assign the flowLayout to your mainWindow?
Yes, this is what I did at the first place but I followed the suggestion of @JKSH for implementing the scrollArea for all button widgets.Then you should: Put the flowLayout in a container/child widget Put that container/child widget in the scrollArea
So, I put the entire flowlayout inside a flowWidget.
Note: scrollArea can handle one entire widget (with all of its sub-widgets and layouts). As far as I understood, your buttons are on multiple widgets, am I right?!
Yes, my buttons are arrays of widgets. I want to enable scrolling property just the way I use this link of this forum ; to be able to navigate from top to bottom of this page where the contents of my windows are buttons.Don't know how your "scroll from top buttons down to bottom buttons" should work. At least when the entire widgets is as big as the parent window.
I want to navigate to the bottom of the mainwindow through the scrollbar where the contents of the mainWindow are buttons , just like the following picture; scrollbar in the bottom and right side. In the figure, there are 20 push buttons but I can only view 12 out of them in my window.
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
where the contents of the mainWindow are buttons
The content (= centralwidget) of your mainWindow should be your scrollArea then. And inside this scrollArea you place the widget with your buttons.
-
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
where the contents of the mainWindow are buttons
The content (= centralwidget) of your mainWindow should be your scrollArea then. And inside this scrollArea you place the widget with your buttons.
@Pl45m4
The content (= centralwidget) of your mainWindow should be your scrollArea then. And inside this scrollArea you place the widget with your buttons.
Okay, Let me write the whole function according to your suggestion.Window::Window() { QMainWindow *a= new QMainWindow(this); QWidget *flowWidget = new QWidget(); FlowLayout *flowLayout = new FlowLayout(); flowWidget->setLayout(flowLayout); int n=20; QVector <QPushButton *> buttons(n); for (int ii=0;ii<n;ii++) { QPushButton * pb = new QPushButton(); // creating buttons pb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb); } QScrollArea *scroll =new QScrollArea(); scroll->setWidget(flowWidget); a->setCentralWidget(scroll); a->show(); setWindowTitle(tr("Flow Layout")); }
I obviously,get 2 windows from the above code,
Window1
corresponding tothis
by default window which is blank.
Window2
is as shown below
scroll Area is applied to the window but the flowLayout seems not to be working and the widgets take vertical Layout. Can you help me to fix this?
-
@Pl45m4
The content (= centralwidget) of your mainWindow should be your scrollArea then. And inside this scrollArea you place the widget with your buttons.
Okay, Let me write the whole function according to your suggestion.Window::Window() { QMainWindow *a= new QMainWindow(this); QWidget *flowWidget = new QWidget(); FlowLayout *flowLayout = new FlowLayout(); flowWidget->setLayout(flowLayout); int n=20; QVector <QPushButton *> buttons(n); for (int ii=0;ii<n;ii++) { QPushButton * pb = new QPushButton(); // creating buttons pb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb); } QScrollArea *scroll =new QScrollArea(); scroll->setWidget(flowWidget); a->setCentralWidget(scroll); a->show(); setWindowTitle(tr("Flow Layout")); }
I obviously,get 2 windows from the above code,
Window1
corresponding tothis
by default window which is blank.
Window2
is as shown below
scroll Area is applied to the window but the flowLayout seems not to be working and the widgets take vertical Layout. Can you help me to fix this?
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
Window::Window()
{
QMainWindow *a= new QMainWindow(this);QWidget *flowWidget = new QWidget();
FlowLayout *flowLayout = new FlowLayout();
flowWidget->setLayout(flowLayout);
int n=20;
QVector <QPushButton *> buttons(n);for (int ii=0;ii<n;ii++)
{
QPushButton * pb = new QPushButton(); // creating buttonspb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb);
}
QScrollArea *scroll =new QScrollArea();
scroll->setWidget(flowWidget);a->setCentralWidget(scroll);
a->show();
That's not what I suggested....
The window with the title
flowLayout
IS yourMainWindow
, right?! Why you created another one ?I obviously,get 2 windows from the above code, Window1 corresponding to this by default window which is blank.
Yes, not very surprising from above code...
Window::Window()
What is this class? Your first
mainWindow
? Then you dont need to create anotherQMainWindow *a= new QMainWindow(this);
inside this class. Remove it and callthis->setCentralWidget(....)
instead (assumingWindow
is aQMainWindow
class). -
@Pl45m4
The content (= centralwidget) of your mainWindow should be your scrollArea then. And inside this scrollArea you place the widget with your buttons.
Okay, Let me write the whole function according to your suggestion.Window::Window() { QMainWindow *a= new QMainWindow(this); QWidget *flowWidget = new QWidget(); FlowLayout *flowLayout = new FlowLayout(); flowWidget->setLayout(flowLayout); int n=20; QVector <QPushButton *> buttons(n); for (int ii=0;ii<n;ii++) { QPushButton * pb = new QPushButton(); // creating buttons pb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb); } QScrollArea *scroll =new QScrollArea(); scroll->setWidget(flowWidget); a->setCentralWidget(scroll); a->show(); setWindowTitle(tr("Flow Layout")); }
I obviously,get 2 windows from the above code,
Window1
corresponding tothis
by default window which is blank.
Window2
is as shown below
scroll Area is applied to the window but the flowLayout seems not to be working and the widgets take vertical Layout. Can you help me to fix this?
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
scroll Area is applied to the window but the flowLayout seems not to be working and the widgets take vertical Layout. Can you help me to fix this?
Your
flowWidget
is too narrow -- that's why the flow layout can't put buttons side-by-side. Give it a larger minimum width.Remember: The width of the QScrollArea is not the same as the width of the widget it holds
-
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
Window::Window()
{
QMainWindow *a= new QMainWindow(this);QWidget *flowWidget = new QWidget();
FlowLayout *flowLayout = new FlowLayout();
flowWidget->setLayout(flowLayout);
int n=20;
QVector <QPushButton *> buttons(n);for (int ii=0;ii<n;ii++)
{
QPushButton * pb = new QPushButton(); // creating buttonspb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb);
}
QScrollArea *scroll =new QScrollArea();
scroll->setWidget(flowWidget);a->setCentralWidget(scroll);
a->show();
That's not what I suggested....
The window with the title
flowLayout
IS yourMainWindow
, right?! Why you created another one ?I obviously,get 2 windows from the above code, Window1 corresponding to this by default window which is blank.
Yes, not very surprising from above code...
Window::Window()
What is this class? Your first
mainWindow
? Then you dont need to create anotherQMainWindow *a= new QMainWindow(this);
inside this class. Remove it and callthis->setCentralWidget(....)
instead (assumingWindow
is aQMainWindow
class).@Pl45m4 said in Syntax for Vector of QPushbuttons added to FlowLayout:
Actually, I'm using the example file of flowLayout given in the section of Examples in Qt Creator where classWindow
used [subclass of QWidget].The window with the title
flowLayout
IS yourMainWindow
, right?! Why you created another one ?
As you can see, there are two windows with names asflowLayout
andFlowLayout
. My mainwindow should beFlow Layout
for which I wrote the following code:
I needed to add scroll functionality to the following code.#include<QScrollArea> Window::Window { FlowLayout *flowLayout = new FlowLayout(this); int n=20; QVector <QPushButton *> buttons(n); for (int ii=0;ii<n;ii++) { QPushButton * pb = new QPushButton(this); // creating buttons pb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb); } this ->show(); }
What is this class? Your first
mainWindow
? Then you dont need to create anotherQMainWindow *a= new QMainWindow(this);
inside this class. Remove it and callthis->setCentralWidget(....)
instead (assumingWindow
is aQMainWindow
class).
I usedQMainWindow *a= new QMainWindow(this);
because it seemed to be working partially. -
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
Window::Window()
{
QMainWindow *a= new QMainWindow(this);QWidget *flowWidget = new QWidget();
FlowLayout *flowLayout = new FlowLayout();
flowWidget->setLayout(flowLayout);
int n=20;
QVector <QPushButton *> buttons(n);for (int ii=0;ii<n;ii++)
{
QPushButton * pb = new QPushButton(); // creating buttonspb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb);
}
QScrollArea *scroll =new QScrollArea();
scroll->setWidget(flowWidget);a->setCentralWidget(scroll);
a->show();
That's not what I suggested....
The window with the title
flowLayout
IS yourMainWindow
, right?! Why you created another one ?I obviously,get 2 windows from the above code, Window1 corresponding to this by default window which is blank.
Yes, not very surprising from above code...
Window::Window()
What is this class? Your first
mainWindow
? Then you dont need to create anotherQMainWindow *a= new QMainWindow(this);
inside this class. Remove it and callthis->setCentralWidget(....)
instead (assumingWindow
is aQMainWindow
class).@Pl45m4 said in Syntax for Vector of QPushbuttons added to FlowLayout:
inside this class. Remove it and call
this->setCentralWidget(....)
instead (assumingWindow
is aQMainWindow
class).this->setCentralWidget(....)
this gives me error asthis
is an object ofWindow
class which is a subclass ofQWidget
.
setCentralWidget(.....)
can be applied to the object ofQMainWindow
. -
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
scroll Area is applied to the window but the flowLayout seems not to be working and the widgets take vertical Layout. Can you help me to fix this?
Your
flowWidget
is too narrow -- that's why the flow layout can't put buttons side-by-side. Give it a larger minimum width.Remember: The width of the QScrollArea is not the same as the width of the widget it holds
@JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:
YourflowWidget
is too narrow -- that's why the flow layout can't put buttons side-by-side. Give it a larger minimum width.
Remember: The width of the QScrollArea is not the same as the width of the widget it holdsThis works like a charm! Thanks a ton! I was thinking it to be the fault of my design and made it too complicated.
Just a doubt about the number of buttons appearing/row.
Window::Window { QMainWindow *a= new QMainWindow(this); QWidget *flowWidget = new QWidget(); FlowLayout *flowLayout = new FlowLayout(); flowWidget->setLayout(flowLayout); flowWidget ->setMinimumSize(1200,1200); int n=20; QVector <QPushButton *> buttons(n); for (int ii=0;ii<n;ii++) { QPushButton * pb = new QPushButton(); // creating buttons pb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb); } QScrollArea *scroll =new QScrollArea(); scroll->setWidget(flowWidget); a->setCentralWidget(scroll); a->show(); }
This is the result I get in
flowLayout
window.
From the figure, I get 5 buttons per row but as per the following lines , shouldn't I be getting 6 buttons/row ( 1200/200=6)
flowWidget ->setMinimumSize(1200,1200); // size of widget pb->setMinimumSize(200,200); //size of buttons
-
@JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:
YourflowWidget
is too narrow -- that's why the flow layout can't put buttons side-by-side. Give it a larger minimum width.
Remember: The width of the QScrollArea is not the same as the width of the widget it holdsThis works like a charm! Thanks a ton! I was thinking it to be the fault of my design and made it too complicated.
Just a doubt about the number of buttons appearing/row.
Window::Window { QMainWindow *a= new QMainWindow(this); QWidget *flowWidget = new QWidget(); FlowLayout *flowLayout = new FlowLayout(); flowWidget->setLayout(flowLayout); flowWidget ->setMinimumSize(1200,1200); int n=20; QVector <QPushButton *> buttons(n); for (int ii=0;ii<n;ii++) { QPushButton * pb = new QPushButton(); // creating buttons pb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb); } QScrollArea *scroll =new QScrollArea(); scroll->setWidget(flowWidget); a->setCentralWidget(scroll); a->show(); }
This is the result I get in
flowLayout
window.
From the figure, I get 5 buttons per row but as per the following lines , shouldn't I be getting 6 buttons/row ( 1200/200=6)
flowWidget ->setMinimumSize(1200,1200); // size of widget pb->setMinimumSize(200,200); //size of buttons
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
From the figure, I get 5 buttons per row but as per the following lines , shouldn't I be getting 6 buttons/row ( 1200/200=6)
And you see that the widgets have some margins between them? So why should 6 widgets with 200x each + margins fit into 1200px??
-
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
From the figure, I get 5 buttons per row but as per the following lines , shouldn't I be getting 6 buttons/row ( 1200/200=6)
And you see that the widgets have some margins between them? So why should 6 widgets with 200x each + margins fit into 1200px??
@Christian-Ehrlicher That's right but by intuition/observation, I can say that, in the above figure, one more button can easily fit in. What do you think?
-
@Christian-Ehrlicher That's right but by intuition/observation, I can say that, in the above figure, one more button can easily fit in. What do you think?
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
by intuition/observation, I can say that, in the above figure, one more button can easily fit in.
Apply the same intuition to your previous case:
Then, apply the same explanation that I gave you in my previous post.
Then, explain to us what's happening.
This works like a charm! Thanks a ton! I was thinking it to be the fault of my design and made it too complicated.
Great!
Complicated design does not cause code to stop working. However, it does make life very difficult for you.
Window::Window { QMainWindow *a= new QMainWindow(this);
You are making your design extremely complicated again... You don't need a
Window
plus aQMainWindow
plus aQScrollArea
.Before you proceed any further, simplify your design first!
-
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
by intuition/observation, I can say that, in the above figure, one more button can easily fit in.
Apply the same intuition to your previous case:
Then, apply the same explanation that I gave you in my previous post.
Then, explain to us what's happening.
This works like a charm! Thanks a ton! I was thinking it to be the fault of my design and made it too complicated.
Great!
Complicated design does not cause code to stop working. However, it does make life very difficult for you.
Window::Window { QMainWindow *a= new QMainWindow(this);
You are making your design extremely complicated again... You don't need a
Window
plus aQMainWindow
plus aQScrollArea
.Before you proceed any further, simplify your design first!
@JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
by intuition/observation, I can say that, in the above figure, one more button can easily fit in.
Apply the same intuition to your previous case:
Then, apply the same explanation that I gave you in my previous post.
Then, explain to us what's happening.In this case , the setminimumsize() for the widget is not used ,that's why the buttons take a vertical layout.
You are making your design extremely complicated again... You don't need a
Window
plus aQMainWindow
plus aQScrollArea
.Before you proceed any further, simplify your design first!With the objects of
QMainWindow
,QScrollArea
, I am getting the desired result as I have suppressed /commentedwindow.show();
inmain.cpp
Follow
main.cpp
below:#include <QApplication> #include "window.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Window window; #if defined(Q_OS_SYMBIAN) window.showMaximized(); #else //window.show(); #endif return app.exec(); }
-
@JKSH said in Syntax for Vector of QPushbuttons added to FlowLayout:
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
by intuition/observation, I can say that, in the above figure, one more button can easily fit in.
Apply the same intuition to your previous case:
Then, apply the same explanation that I gave you in my previous post.
Then, explain to us what's happening.In this case , the setminimumsize() for the widget is not used ,that's why the buttons take a vertical layout.
You are making your design extremely complicated again... You don't need a
Window
plus aQMainWindow
plus aQScrollArea
.Before you proceed any further, simplify your design first!With the objects of
QMainWindow
,QScrollArea
, I am getting the desired result as I have suppressed /commentedwindow.show();
inmain.cpp
Follow
main.cpp
below:#include <QApplication> #include "window.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); Window window; #if defined(Q_OS_SYMBIAN) window.showMaximized(); #else //window.show(); #endif return app.exec(); }
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
I am getting the desired result as I have suppressed /commented window.show(); in main.cpp
Because your Window creates and shows a new QMainWindow! Why?!
I think you was already told several times that there is no need to create two windows.
Why don't you removeQMainWindow *a= new QMainWindow(this);
and show Window?
-
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
by intuition/observation, I can say that, in the above figure, one more button can easily fit in.
Apply the same intuition to your previous case:
Then, apply the same explanation that I gave you in my previous post.
Then, explain to us what's happening.
This works like a charm! Thanks a ton! I was thinking it to be the fault of my design and made it too complicated.
Great!
Complicated design does not cause code to stop working. However, it does make life very difficult for you.
Window::Window { QMainWindow *a= new QMainWindow(this);
You are making your design extremely complicated again... You don't need a
Window
plus aQMainWindow
plus aQScrollArea
.Before you proceed any further, simplify your design first!
@JKSH Now, I'm trying out the second part of this design
You can see the bigger red-rectangle is what I was designing above. Now,I've to design the whole layout.Here's my code-
Window::Window()
{ QMainWindow *a= new QMainWindow(this); QWidget *WindowWidget= new QWidget(); WindowWidget->setMinimumSize(2000,2000); QVBoxLayout *WindowLayout = new QVBoxLayout(WindowWidget); QScrollArea *scroll =new QScrollArea(); QLabel *WindowHeading = new QLabel("Experimenting with Scrollbar in Flow Layout"); WindowLayout->addWidget(WindowHeading); WindowLayout->setAlignment(WindowHeading,Qt::AlignCenter); QWidget *flowWidget = new QWidget(); FlowLayout *flowLayout = new FlowLayout(); int n=20; QVector <QPushButton *> buttons(n); for (int ii=0;ii<n;ii++) { QPushButton * pb = new QPushButton(); // creating buttons pb->setMinimumSize(200,200); buttons.push_back(pb); // adding buttons to qvector flowLayout->addWidget(pb); } flowWidget->setLayout(flowLayout); flowWidget ->setMinimumSize(1200,1200); WindowLayout->addWidget(flowWidget); //scroll->setWidget(flowWidget); a->setCentralWidget(WindowWidget); a->show(); }
can't see it working! :'(
-
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
I am getting the desired result as I have suppressed /commented window.show(); in main.cpp
Because your Window creates and shows a new QMainWindow! Why?!
I think you was already told several times that there is no need to create two windows.
Why don't you removeQMainWindow *a= new QMainWindow(this);
and show Window?
@jsulm said in Syntax for Vector of QPushbuttons added to FlowLayout:
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
I am getting the desired result as I have suppressed /commented window.show(); in main.cpp
Because your Window creates and shows a new QMainWindow! Why?!
I think you was already told several times that there is no need to create two windows.Why don't you remove
QMainWindow *a= new QMainWindow(this);
?
As already mentioned before,Window
class is a sub-class ofQWidget
,for setting scrolling option , I need the object ofQMainWindow
, that's the reason why I created the objecta
ofQMainWindow
. -
@jsulm said in Syntax for Vector of QPushbuttons added to FlowLayout:
@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
I am getting the desired result as I have suppressed /commented window.show(); in main.cpp
Because your Window creates and shows a new QMainWindow! Why?!
I think you was already told several times that there is no need to create two windows.Why don't you remove
QMainWindow *a= new QMainWindow(this);
?
As already mentioned before,Window
class is a sub-class ofQWidget
,for setting scrolling option , I need the object ofQMainWindow
, that's the reason why I created the objecta
ofQMainWindow
.@Swati777999 said in Syntax for Vector of QPushbuttons added to FlowLayout:
I need the object of QMainWindow
Then your Window should subclass QMainWindow, not QWidget...