]> sigrok.org Git - pulseview.git/commitdiff
QHexView: Improve vertical slider handling
authorSoeren Apel <redacted>
Sun, 15 Dec 2019 16:23:49 +0000 (17:23 +0100)
committerUwe Hermann <redacted>
Mon, 16 Dec 2019 23:19:57 +0000 (00:19 +0100)
pv/views/decoder_output/QHexView.cpp

index ca2d91b572b7efe3b7ecc2c14b56f6921e4357d8..82b1cd90769e6ca9c839b2b224ddad7b235f5d33 100644 (file)
@@ -173,10 +173,12 @@ uint8_t QHexView::get_next_byte(bool* is_next_chunk)
 
 QSize QHexView::getFullSize() const
 {
-       size_t width = posAscii_ + (BYTES_PER_LINE * charWidth_) +
-               GAP_ASCII_SLIDER + verticalScrollBar()->width();
+       size_t width = posAscii_ + (BYTES_PER_LINE * charWidth_);
 
-       if (!data_)
+       if (verticalScrollBar()->isEnabled())
+               width += GAP_ASCII_SLIDER + verticalScrollBar()->width();
+
+       if (!data_ || (data_size_ == 0))
                return QSize(width, 0);
 
        size_t height = data_size_ / BYTES_PER_LINE;
@@ -199,8 +201,13 @@ void QHexView::paintEvent(QPaintEvent *event)
        setMaximumWidth(widgetSize.width());
        QSize areaSize = viewport()->size();
 
-       verticalScrollBar()->setPageStep(areaSize.height() / charHeight_);
-       verticalScrollBar()->setRange(0, (widgetSize.height() - areaSize.height()) / charHeight_ + 1);
+       // Only show scrollbar if the content goes beyond the visible area
+       if (widgetSize.height() > areaSize.height()) {
+               verticalScrollBar()->setEnabled(true);
+               verticalScrollBar()->setPageStep(areaSize.height() / charHeight_);
+               verticalScrollBar()->setRange(0, ((widgetSize.height() - areaSize.height())) / charHeight_ + 1);
+       } else
+               verticalScrollBar()->setEnabled(false);
 
        // Fill widget background
        painter.fillRect(event->rect(), palette().color(QPalette::Base));