I have created a class that I am calling from another class that deals with the user interface for my program.
The called class sets up a scrollable area that contains 2 QPushbuttons at this point to test it, and it works fine, however I am uneasy that what I have done is not quite correct, and I was wondering if someone could give me feedback on if it is correct, and how to improve it.
At this point I have made the 2 buttons very large (in height) only so that I can see that the effect of the scrolling action is working, which it is.
My concern is that I get the feeling that within the class, I am creating a widget again, even though it inherits a QWidget already, and so this shouldn't be needed.
Note that my code is based on code that I found online, and modified.
#include "stoppagereasons.h"
#include <QPushButton>
#include <QGridLayout>
#include <QScrollBar>
#include <QVBoxLayout>
#include <QScrollArea>
StoppageReasons
::StoppageReasons(QWidget *parent
){
btn->setFixedSize(100,500);
btn2->setFixedSize(100,500);
layout->addWidget(btn);
layout->addWidget(btn2);
widget->setLayout(layout);
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->setWidgetResizable(false);
scroll->setWidget(widget);
vLayout->addWidget(scroll);
setLayout(vLayout);
}
#include "stoppagereasons.h"
#include <QPushButton>
#include <QGridLayout>
#include <QScrollBar>
#include <QVBoxLayout>
#include <QScrollArea>
StoppageReasons::StoppageReasons(QWidget *parent)
: QWidget(parent)
{
QWidget *widget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout();
QPushButton *btn = new QPushButton("test");
btn->setFixedSize(100,500);
QPushButton *btn2 = new QPushButton("test2");
btn2->setFixedSize(100,500);
layout->addWidget(btn);
layout->addWidget(btn2);
widget->setLayout(layout);
QScrollArea *scroll = new QScrollArea;
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->setWidgetResizable(false);
scroll->setWidget(widget);
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->addWidget(scroll);
setLayout(vLayout);
}
To copy to clipboard, switch view to plain text mode
Bookmarks