QScrollarea in verticalLayout
-
wrote on 6 Jul 2018, 06:33 last edited by
Can not scroll the buttons created using Vertical Layout.
widget.cpp
#include "widget.h" #include "ui_widget.h" #include<QScrollArea> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); QScrollArea *area=new QScrollArea(this); area->setLayout(ui->verticalLayout); } Widget::~Widget() { delete ui; }
-
Can not scroll the buttons created using Vertical Layout.
widget.cpp
#include "widget.h" #include "ui_widget.h" #include<QScrollArea> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); QScrollArea *area=new QScrollArea(this); area->setLayout(ui->verticalLayout); } Widget::~Widget() { delete ui; }
output:
Moderatorswrote on 6 Jul 2018, 06:36 last edited by raven-worx 7 Jun 2018, 06:36@hjohn said in QScrollarea in verticalLayout:
QScrollArea *area=new QScrollArea(this);
area->setLayout(ui->verticalLayout);because thats not how you set content to a QScrollArea.
You should use QScrollArea::setWidget() -
@hjohn said in QScrollarea in verticalLayout:
QScrollArea *area=new QScrollArea(this);
area->setLayout(ui->verticalLayout);because thats not how you set content to a QScrollArea.
You should use QScrollArea::setWidget()wrote on 6 Jul 2018, 06:47 last edited by@raven-worx
which widget i have to set?
I mean first i am adding layout and then adding buttons on it from Qt designer -
@raven-worx
which widget i have to set?
I mean first i am adding layout and then adding buttons on it from Qt designer@hjohn said in QScrollarea in verticalLayout:
which widget i have to set?
any widget.
QWidget* w = new QWidget( this ); w->setLayout(ui->verticalLayout); QScrollArea *area = new QScrollArea(this); area->setWidget(w);
-
@hjohn said in QScrollarea in verticalLayout:
which widget i have to set?
any widget.
QWidget* w = new QWidget( this ); w->setLayout(ui->verticalLayout); QScrollArea *area = new QScrollArea(this); area->setWidget(w);
wrote on 6 Jul 2018, 07:07 last edited by@raven-worx Its Done..Thank you very much for quick reply.thanks for Help. :)
-
wrote on 6 Jul 2018, 08:52 last edited by
widget.cpp
#include "widget.h" #include "ui_widget.h" #include<QScrollArea> #include<QPushButton> #include<QDebug> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); QWidget *W=new QWidget(this); W->setLayout(ui->verticalLayout); QScrollArea *area=new QScrollArea(this); area->setWidget(W); } Widget::~Widget() { delete ui; }
as its visible in the image , it doesn't look proper. How do I fix it ?
-
widget.cpp
#include "widget.h" #include "ui_widget.h" #include<QScrollArea> #include<QPushButton> #include<QDebug> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); QWidget *W=new QWidget(this); W->setLayout(ui->verticalLayout); QScrollArea *area=new QScrollArea(this); area->setWidget(W); } Widget::~Widget() { delete ui; }
output :
as its visible in the image , it doesn't look proper. How do I fix it ?
@hjohn said in QScrollarea in verticalLayout:
it doesn't look proper. How do I fix it ?
define proper. What exactly do you want to achieve?
-
@hjohn said in QScrollarea in verticalLayout:
it doesn't look proper. How do I fix it ?
define proper. What exactly do you want to achieve?
wrote on 6 Jul 2018, 09:01 last edited by hjohn 7 Jun 2018, 09:05@raven-worx Proper:Without horizontal scrollBar, I mean if we want to see the whole button we have to scroll . I don't want to scroll horizontally.
-
wrote on 6 Jul 2018, 09:07 last edited by
Okay its done ,
I just resized the QScrollArea.
Thanks all. -
Hi,
Since you are using Designer, why don't you put the QScrollArea directly in your ui ?
-
Why is that ?
-
Then I'd recommend to start by doing the whole interface in code only. Once you are confortable with that, you can start mixing designer and code generate widgets.
There are subtleties when mixing that you have to take into account.
-
Then I'd recommend to start by doing the whole interface in code only. Once you are confortable with that, you can start mixing designer and code generate widgets.
There are subtleties when mixing that you have to take into account.
1/15