diff --git a/selfdrive/ui/qt/text.cc b/selfdrive/ui/qt/text.cc index d44570d99d..d613ee6e9e 100644 --- a/selfdrive/ui/qt/text.cc +++ b/selfdrive/ui/qt/text.cc @@ -6,17 +6,22 @@ #include "qt_window.hpp" #include "selfdrive/hardware/hw.h" +#include "widgets/scrollview.hpp" int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget window; setMainWindow(&window); - QVBoxLayout *layout = new QVBoxLayout(); - layout->setContentsMargins(125, 125, 125, 125); + QGridLayout *layout = new QGridLayout; + layout->setMargin(50); - // TODO: make this scroll - layout->addWidget(new QLabel(argv[1]), 0, Qt::AlignTop); + QLabel *label = new QLabel(argv[1]); + label->setWordWrap(true); + label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); + ScrollView *scroll = new ScrollView(label); + scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + layout->addWidget(scroll, 0, 0, Qt::AlignTop); QPushButton *btn = new QPushButton(); #ifdef __aarch64__ @@ -28,7 +33,7 @@ int main(int argc, char *argv[]) { btn->setText("Exit"); QObject::connect(btn, SIGNAL(released()), &a, SLOT(quit())); #endif - layout->addWidget(btn, 0, Qt::AlignRight); + layout->addWidget(btn, 0, 0, Qt::AlignRight | Qt::AlignBottom); window.setLayout(layout); window.setStyleSheet(R"( @@ -44,6 +49,7 @@ int main(int argc, char *argv[]) { padding-left: 100px; border: 2px solid white; border-radius: 20px; + margin-right: 40px; } )"); diff --git a/selfdrive/ui/qt/widgets/scrollview.cc b/selfdrive/ui/qt/widgets/scrollview.cc index 167d0da845..b58e4bb53e 100644 --- a/selfdrive/ui/qt/widgets/scrollview.cc +++ b/selfdrive/ui/qt/widgets/scrollview.cc @@ -1,3 +1,4 @@ +#include #include "scrollview.hpp" ScrollView::ScrollView(QWidget *w, QWidget *parent) : QScrollArea(parent){ @@ -7,6 +8,29 @@ ScrollView::ScrollView(QWidget *w, QWidget *parent) : QScrollArea(parent){ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setStyleSheet("ScrollView { background-color:transparent; }"); + QString style = R"( + QScrollBar:vertical { + border: none; + background: transparent; + width:10px; + margin: 0; + } + QScrollBar::handle:vertical { + min-height: 0px; + border-radius: 4px; + background-color: white; + } + QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { + height: 0px; + } + QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { + background: none; + } + )"; + + verticalScrollBar()->setStyleSheet(style); + horizontalScrollBar()->setStyleSheet(style); + QScroller *scroller = QScroller::scroller(this->viewport()); QScrollerProperties sp = scroller->scrollerProperties();