0% found this document useful (0 votes)
6 views4 pages

Bottom Bar

This document defines a C++ Widget class that contains properties and methods for displaying a multi-page sheet selector. It initializes stylesheets for selected and unselected sheet indicators. It then constructs the UI by adding labeled widget buttons for each sheet and applying the appropriate styles, as well as expanding borders.

Uploaded by

sriramshiyam04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Bottom Bar

This document defines a C++ Widget class that contains properties and methods for displaying a multi-page sheet selector. It initializes stylesheets for selected and unselected sheet indicators. It then constructs the UI by adding labeled widget buttons for each sheet and applying the appropriate styles, as well as expanding borders.

Uploaded by

sriramshiyam04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#ifndef WIDGET_H

#define WIDGET_H

#include <QWidget>
#include <QLabel>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget


{
Q_OBJECT

public:
Widget(QWidget *parent = nullptr);
~Widget();

QSize startingWidgetSize = QSize(20, 32);


QSize boxSize = QSize(80, 32);
QSize bottomBoxSize = QSize(80, 8);

int selectedSheet = 1;
int totalSheets = 15;
QString selectedLeftStyle = "#box {background: #F1F2F1; border-top-right-radius: 8px; border-
top: 1px solid rgba(0, 0, 0, 0.2); border-right: 1px solid rgba(0, 0, 0, 0.2); }";
QString selectedRightStyle = "#box {background: #F1F2F1; border-top-left-radius: 8px; border-
top: 1px solid rgba(0, 0, 0, 0.2); border-left: 1px solid rgba(0, 0, 0, 0.2); }";
QString selectedStyle = "#box {background: white;}";
QString nonSelectedLeftStyle = "#box {background: #F1F2F1; border-top: 1px solid rgba(0, 0,
0, 0.2); border-right: 1px solid rgba(0, 0, 0, 0.2);}";
QString nonSelectedRightStyle = "#box {background: #F1F2F1; border-top: 1px solid rgba(0, 0,
0, 0.2); border-left: 1px solid rgba(0, 0, 0, 0.2);}";
QString bottomBoxStyle = "#box {background: white; border-bottom-right-radius: 8px; border-
bottom-left-radius: 8px; border-bottom: 1px solid rgba(0, 0, 0, 0.2); border-left: 1px solid rgba(0, 0,
0, 0.2); border-right: 1px solid rgba(0, 0, 0, 0.2);}";

QList<QLabel*> sheetNames;
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
#include "widget.h"
#include "./ui_widget.h"
#include <QHBoxLayout>
#include <QScrollArea>
#include <QStyleOption>
#include <QPainter>

class CustomWidget : public QWidget{


Q_OBJECT
signals:
void clicked();

private:
void paintEvent(QPaintEvent *) override
{
QStyleOption opt;
opt.initFrom (this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
};

Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);

QScrollArea *scrollArea = new QScrollArea(this);


scrollArea->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
scrollArea->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
scrollArea->setFixedWidth (width ());
scrollArea->setStyleSheet ("border: 0;");

QWidget *container = new QWidget();


scrollArea->setWidget (container);
container->setFixedHeight (boxSize.height ()+bottomBoxSize.height ());
scrollArea->setWidgetResizable (true);

QVBoxLayout *vbox2 = new QVBoxLayout();


vbox2->setContentsMargins (0 ,0, 0, 0);
vbox2->setSpacing (0);
container->setLayout (vbox2);

QWidget *sheetBoxes = new QWidget();


sheetBoxes->setFixedHeight (30);
sheetBoxes->setStyleSheet ("background: white;");
vbox2->addWidget (sheetBoxes);

QHBoxLayout *hbox = new QHBoxLayout();


hbox->setAlignment (Qt::AlignTop);
hbox->setContentsMargins (0 ,0, 0, 0);
hbox->setSpacing (0);
sheetBoxes->setLayout (hbox);

QWidget *startingWidget = new QWidget();


startingWidget->setObjectName ("box");
startingWidget->setFixedSize (startingWidgetSize);
startingWidget->setStyleSheet (nonSelectedLeftStyle);
hbox->addWidget (startingWidget);

QString style;

for (int i = 0; i < totalSheets; ++i) {


CustomWidget *widget = new CustomWidget();
widget->setCursor (Qt::PointingHandCursor);
widget->setObjectName ("box");
widget->setFixedSize (boxSize);

QVBoxLayout *vbox = new QVBoxLayout();


vbox->setContentsMargins (0, 0, 0, 0);
vbox->setSpacing (0);
widget->setLayout (vbox);

QLabel *label = new QLabel(QString::fromStdString ("Sheet" + std::to_string (i + 1)));


label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
label->setStyleSheet ("background: rgba(0,0,0,0); font-size: 14px;");
vbox->addWidget (label);
vbox->setAlignment (label, Qt::AlignHCenter);

sheetNames.push_back (label);

QObject::connect (widget, &CustomWidget::clicked, [=]() {


qDebug() << label->text ();
});

if (i < selectedSheet) {
style = nonSelectedLeftStyle;
if (selectedSheet - i == 1) {
style = selectedLeftStyle;
}
} else if (i > selectedSheet) {
style = nonSelectedRightStyle;
if (i - selectedSheet == 1) {
style = selectedRightStyle;
}
} else if (i == selectedSheet) {
style = selectedStyle;
}

widget->setStyleSheet (style);
hbox->addWidget (widget);
}
QWidget *expandingWidget = new QWidget();
expandingWidget->setObjectName ("box");
expandingWidget->setStyleSheet (nonSelectedRightStyle);
expandingWidget->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);

hbox->addWidget (expandingWidget);

QWidget *sheetBoxes2 = new QWidget();


sheetBoxes2->setStyleSheet ("background: #F1F2F1;");
sheetBoxes2->setFixedHeight (15);
vbox2->addWidget (sheetBoxes2);

QWidget *box = new QWidget(sheetBoxes2);


box->setObjectName ("box");
box->setFixedSize (bottomBoxSize);
box->move (100, 0);
box->setStyleSheet (bottomBoxStyle);
}

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

You might also like