Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScrollBar edges on all sides
Forum Updated to NodeBB v4.3 + New Features

QScrollBar edges on all sides

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 7 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    What version of Qt ?
    On what OS ?
    If Linux, what desktop environment ?
    Can you show a picture of what you get ?

    You should provide a minimal compilable example that reproduces that behaviour.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Phil K
      wrote on last edited by Phil K
      #3

      Currently using Qt 5.13.2 on Linux under Gnome, but I cross-compile to Windows with I think Qt 5.12 and see similar behavior. I linked a picture below. Left side is a vanilla table widget with its scrollbars displayed. Right side is another table widget, but with external scrollbars. Look at the edges of the external scrollbars at right. There is no bottom edge on the horizontal nor a right edge on the vertical. I want those scrollbars to look just like the scrollbars on the left side.

      #include "mainwindow.h"
      
      #include <QtWidgets/QGridLayout>
      #include <QtWidgets/QHeaderView>
      #include <QtWidgets/QScrollBar>
      #include <QtWidgets/QTableWidget>
      
      MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
      {
          QGridLayout *grid = new QGridLayout();
          QWidget *central = new QWidget();
      
          // Left side of the grid is a default table widget using its scrollbars
          QTableWidget *table1 = new QTableWidget(20, 5, this);
          for (int col = 0; col < 5; ++col) {
              QTableWidgetItem *header_item = new QTableWidgetItem(QString("Column %1").arg(col));
              table1->setHorizontalHeaderItem(col, header_item);
              for (int row = 0; row < 20; ++row) {
                  QTableWidgetItem *item = new QTableWidgetItem(QString("(%1, %2)").arg(row).arg(col));
                  table1->setItem(row, col, item);
              }
          }
          table1->resizeRowsToContents();
          grid->addWidget(table1, 0, 0);
      
          // Right side of the grid is a table widget with external scrollbars
          QTableWidget *table2 = new QTableWidget(20, 5, this);
          table2->verticalHeader()->setVisible(false);
          table2->horizontalScrollBar()->setDisabled(true);
          table2->verticalScrollBar()->setDisabled(true);
          table2->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
          table2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
          for (int col = 0; col < 5; ++col) {
              QTableWidgetItem *header_item = new QTableWidgetItem(QString("Column %1").arg(col));
              table2->setHorizontalHeaderItem(col, header_item);
              for (int row = 0; row < 20; ++row) {
                  QTableWidgetItem *item = new QTableWidgetItem(QString("(%1, %2)").arg(row).arg(col));
                  table2->setItem(row, col, item);
              }
          }
          table2->resizeRowsToContents();
          grid->addWidget(table2, 0, 1);
      
          QScrollBar *h_bar = new QScrollBar(Qt::Horizontal, this);
          grid->addWidget(h_bar, 1, 1);
      
          QScrollBar *v_bar = new QScrollBar(Qt::Vertical, this);
          grid->addWidget(v_bar, 0, 2);
      
          central->setLayout(grid);
          setCentralWidget(central);
      }
      

      scollbars

      J.HilkJ 1 Reply Last reply
      0
      • P Phil K

        When I use a QScrollBar as a separate widget to control the scroll position of several other widgets, I notice there is a visible border or "edge" on only one of its four sides. I happen to notice this when I put my custom widget next to a regular table view. When the table view draws its horizontal scrollbar at bottom, you can plainly see a nice border on the side of the left/right control and on the bottom of the scrollbar. How can I ensure my QScrollBar also draws those edge lines? You can easily reproduce this by dropping a scroll bar widget on a form. There is an edge line only on one of the four sides of the rectangle. Try it with style fusion.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #4

        @Phil-K said in QScrollBar edges on all sides:

        How can I ensure my QScrollBar also draws those edge lines?

        I don't know, but can you reproduce it via stylesheet with border on your own scrollbars?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Phil K
          wrote on last edited by Phil K
          #5

          I was hoping instead that I could possibly use a QFrame parent which might provide the 3 missing edges of the scrollbars, i.e. aligning the horizontal bar child to the bottom of a QFrame parent, but the scrollbar draws over small edge provided by the QFrame.

          1 Reply Last reply
          0
          • P Phil K

            Currently using Qt 5.13.2 on Linux under Gnome, but I cross-compile to Windows with I think Qt 5.12 and see similar behavior. I linked a picture below. Left side is a vanilla table widget with its scrollbars displayed. Right side is another table widget, but with external scrollbars. Look at the edges of the external scrollbars at right. There is no bottom edge on the horizontal nor a right edge on the vertical. I want those scrollbars to look just like the scrollbars on the left side.

            #include "mainwindow.h"
            
            #include <QtWidgets/QGridLayout>
            #include <QtWidgets/QHeaderView>
            #include <QtWidgets/QScrollBar>
            #include <QtWidgets/QTableWidget>
            
            MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
            {
                QGridLayout *grid = new QGridLayout();
                QWidget *central = new QWidget();
            
                // Left side of the grid is a default table widget using its scrollbars
                QTableWidget *table1 = new QTableWidget(20, 5, this);
                for (int col = 0; col < 5; ++col) {
                    QTableWidgetItem *header_item = new QTableWidgetItem(QString("Column %1").arg(col));
                    table1->setHorizontalHeaderItem(col, header_item);
                    for (int row = 0; row < 20; ++row) {
                        QTableWidgetItem *item = new QTableWidgetItem(QString("(%1, %2)").arg(row).arg(col));
                        table1->setItem(row, col, item);
                    }
                }
                table1->resizeRowsToContents();
                grid->addWidget(table1, 0, 0);
            
                // Right side of the grid is a table widget with external scrollbars
                QTableWidget *table2 = new QTableWidget(20, 5, this);
                table2->verticalHeader()->setVisible(false);
                table2->horizontalScrollBar()->setDisabled(true);
                table2->verticalScrollBar()->setDisabled(true);
                table2->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
                table2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
                for (int col = 0; col < 5; ++col) {
                    QTableWidgetItem *header_item = new QTableWidgetItem(QString("Column %1").arg(col));
                    table2->setHorizontalHeaderItem(col, header_item);
                    for (int row = 0; row < 20; ++row) {
                        QTableWidgetItem *item = new QTableWidgetItem(QString("(%1, %2)").arg(row).arg(col));
                        table2->setItem(row, col, item);
                    }
                }
                table2->resizeRowsToContents();
                grid->addWidget(table2, 0, 1);
            
                QScrollBar *h_bar = new QScrollBar(Qt::Horizontal, this);
                grid->addWidget(h_bar, 1, 1);
            
                QScrollBar *v_bar = new QScrollBar(Qt::Vertical, this);
                grid->addWidget(v_bar, 0, 2);
            
                central->setLayout(grid);
                setCentralWidget(central);
            }
            

            scollbars

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #6

            @Phil-K said in QScrollBar edges on all sides:

            grid

            are you sure, your issues aren't simply from the default spacing /margins a layout adds ?

            you can set those to 0, IIRC they are not 0 by default


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            P 1 Reply Last reply
            1
            • J.HilkJ J.Hilk

              @Phil-K said in QScrollBar edges on all sides:

              grid

              are you sure, your issues aren't simply from the default spacing /margins a layout adds ?

              you can set those to 0, IIRC they are not 0 by default

              P Offline
              P Offline
              Phil K
              wrote on last edited by
              #7

              @J-Hilk Yep, set the margins to zero and still the same effect. If you look at the Qt sliders example below from your wiki, you can plainly see the same effect. The QScrollBar draws a perceptible edge on only one of the four sides. I suppose this is by design. It just looks "off" when side-by-side with a table view in which the edges are clearly seen.

              Sliders example

              J.HilkJ 1 Reply Last reply
              0
              • P Phil K

                @J-Hilk Yep, set the margins to zero and still the same effect. If you look at the Qt sliders example below from your wiki, you can plainly see the same effect. The QScrollBar draws a perceptible edge on only one of the four sides. I suppose this is by design. It just looks "off" when side-by-side with a table view in which the edges are clearly seen.

                Sliders example

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #8

                @Phil-K ok, I see

                looks fine on MacOS ;)
                46750232-6fc7-4bdd-929f-9836dc4ad68d-image.png

                So, its probably something you can influence via Style options or stylesheet


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  PIKITASIA
                  Banned
                  wrote on last edited by
                  #9
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    Hi
                    Do You mean this ? ( on windows)
                    alt text

                    P 1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      NIJITASIA
                      Banned
                      wrote on last edited by NIJITASIA
                      #11
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        Hi
                        Do You mean this ? ( on windows)
                        alt text

                        P Offline
                        P Offline
                        Phil K
                        wrote on last edited by
                        #12

                        @mrjj Yes, your arrows are pointing to the 1 pixel edges on the horizontal and vertical that appear to be drawn when the scrollbars are rendered. The other 3 edges on each are not drawn.

                        mrjjM 1 Reply Last reply
                        0
                        • P Phil K

                          @mrjj Yes, your arrows are pointing to the 1 pixel edges on the horizontal and vertical that appear to be drawn when the scrollbars are rendered. The other 3 edges on each are not drawn.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          @Phil-K
                          Ok.
                          Well that is by design as far as i know.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved