PDA

View Full Version : ScrollBar not working in the QScrollArea



gunturrohith
5th February 2016, 12:32
fact.h


#ifndef FACTORYMENU_H
#define FACTORYMENU_H

#include <QDialog>
#include <QScrollArea>
#include <QScrollBar>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>

namespace Ui {
class FactoryMenu;
}

class FactoryMenu : public QDialog
{
Q_OBJECT

public:
explicit FactoryMenu(QWidget *parent = 0);
~FactoryMenu();

private:
Ui::FactoryMenu *ui;
QScrollArea *itemsArea;
QGridLayout *layout;
QVBoxLayout *printerLayout;
QVBoxLayout *lcdLayout;
QVBoxLayout *gsm_gprsLayout;
QVBoxLayout *ifdLayout;
QVBoxLayout *samLayout;
QHBoxLayout *mainLayout;
};

#endif // FACTORYMENU_H

fact.cpp


#include "factorymenu.h"
#include "ui_factorymenu.h"

FactoryMenu::FactoryMenu(QWidget *parent) :
QDialog(parent),
ui(new Ui::FactoryMenu)
{
ui->setupUi(this);
QFrame::WinPanel;
setWindowFlags(Qt::FramelessWindowHint);

ui->checkBox->setFixedSize(3000,150);
ui->checkBox_2->setFixedSize(50,50);
ui->checkBox_3->setFixedSize(50,50);
ui->checkBox_4->setFixedSize(50,50);
ui->checkBox_5->setFixedSize(50,50);
ui->checkBox_6->setFixedSize(50,50);
ui->checkBox_7->setFixedSize(50,50);
ui->checkBox_8->setFixedSize(50,50);
ui->checkBox_9->setFixedSize(50,50);
ui->checkBox_10->setFixedSize(50,50);
ui->checkBox_11->setFixedSize(50,50);
ui->checkBox_12->setFixedSize(50,50);

mainLayout = new QHBoxLayout(ui->scrollWidget);
mainLayout->addWidget(ui->checkBox);
mainLayout->addWidget(ui->checkBox_2);
mainLayout->addWidget(ui->checkBox_3);
mainLayout->addWidget(ui->checkBox_4);
mainLayout->addWidget(ui->checkBox_5);
mainLayout->addWidget(ui->checkBox_6);
mainLayout->addWidget(ui->checkBox_7);
mainLayout->addWidget(ui->checkBox_8);
mainLayout->addWidget(ui->checkBox_9);
mainLayout->addWidget(ui->checkBox_10);
mainLayout->addWidget(ui->checkBox_11);
mainLayout->addWidget(ui->checkBox_12);

// printerLayout->addWidget(ui->checkBox);
// mainLayout->addLayout(printerLayout);
// mainLayout->addLayout(lcdLayout);
// mainLayout->addLayout(gsm_gprsLayout);
// mainLayout->addLayout(ifdLayout);
// mainLayout->addLayout(samLayout);

itemsArea = new QScrollArea(this);
itemsArea->setFocusPolicy(Qt::NoFocus);
itemsArea->setWidget(ui->scrollWidget);
itemsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded );
itemsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
// itemsArea->horizontalScrollBar()->setStyleSheet("width: 30px;");
// itemsArea->verticalScrollBar()->setStyleSheet("width: 30px;");
itemsArea->setGeometry(5,20,0,0);
// itemsArea->setFixedSize(695,421);
itemsArea->setFixedSize(670,411);
itemsArea->setLayout(mainLayout);
itemsArea->setStyleSheet(
"QScrollArea {"
"border: 2px solid;"
"border-radius: 5px;"
"Text-align:center;"
"background-color:;""}");
// itemsArea->setStyleSheet("background-image: url(:/images/menu_bg.jpg)");

}

FactoryMenu::~FactoryMenu()
{
delete ui;
}


Hi i am trying to add around 100 checkboxes to my GUI for the i am trying to use the QScrollArea using the QHBOXLayout
the GUI is showing fine but where as the scrolls are not working
The screen shot of my GUI is also uploaded
Here is my code can any one please where the bug is present
Thanks in advance
Rohith.G

11680

anda_skoa
8th February 2016, 09:29
The scroll area doesn't seem to be in a layout.

In any case, your actual code won't have the checkboxes in the "ui" part, since you are not going to do 100 of them manually.

So my suggestion would be to change that into the actual code right away
1) Add the scroll area to the dialog in Designer, properly layouted
2) Create a QWidget derived class and in its constructor create the checkboxes and put the into the widget's layout
3) In the dialog's constructor create an instance of that class and put it into the scroll area

Cheers,
_

gunturrohith
12th February 2016, 06:37
Thanks It helped me a lot