From 9238fade1822b30407ae0c113c655ce76c158e00 Mon Sep 17 00:00:00 2001 From: iejMac <61431446+iejMac@users.noreply.github.com> Date: Sat, 3 Apr 2021 01:18:26 -0700 Subject: [PATCH] scrolling in text window (#20564) * grid layout + better scrollbar * style * style * tabs * scrollbar behind button fix * alerts background color fix (#20568) * horizontal style + more space for scrollbar * fixes * fixes * fixes * remove background on scroll bar * fix horizontal overflow * indent' Co-authored-by: Comma Device old-commit-hash: 10e4d321977928a7314cd4149ba29ea08798820a --- selfdrive/ui/qt/text.cc | 16 +++++++++++----- selfdrive/ui/qt/widgets/scrollview.cc | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) 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();