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. How to set top margin to QScrollBar in QTableView.
QtWS25 Last Chance

How to set top margin to QScrollBar in QTableView.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsliderqtableviewqscrollarea
4 Posts 3 Posters 3.9k Views
  • 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.
  • T Offline
    T Offline
    tokafr
    wrote on last edited by
    #1

    Hello
    I have an object of QTableView with horizontal header view, and vertical scroll bar.
    the problem is that scroll slider goes with header view also, I want to set properties to scrollbar to be visible it only under header view. I tried this but it doesn't affects.

      QScrollScrollBar *vscroll = new QScrollBar(this);
    
      vscroll -> setAttribute(Qt::WA_OpaquePaintEvent, false);
    
      vscroll -> setContentsMargins(0, 20, 0, 0);
      tableView -> setVerticalScrollBar(vscroll);
    

    any idea?

    raven-worxR 1 Reply Last reply
    0
    • J Offline
      J Offline
      Jan-Willem
      wrote on last edited by
      #2

      Would something like this work?

      QScrollScrollBar *vscroll = tableView -> verticalScrollBar();
      vscroll->setMaximumHeight(tableView->height() - tableView->horizontalHeader()->height());
      vscroll->move(tableView->horizontalHeader()->height(), vscoll->y());
      

      Else you could try it with stylesheets?

      1 Reply Last reply
      0
      • T tokafr

        Hello
        I have an object of QTableView with horizontal header view, and vertical scroll bar.
        the problem is that scroll slider goes with header view also, I want to set properties to scrollbar to be visible it only under header view. I tried this but it doesn't affects.

          QScrollScrollBar *vscroll = new QScrollBar(this);
        
          vscroll -> setAttribute(Qt::WA_OpaquePaintEvent, false);
        
          vscroll -> setContentsMargins(0, 20, 0, 0);
          tableView -> setVerticalScrollBar(vscroll);
        

        any idea?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @tokafr
        i think you wont be successful this way. Since the item view widget just layouts it's widgets (viewport, scrollbars, headerviews, ...) this way. And this happens on every resize and on some other actions.
        And this is hidden in the private part of the item view widget.

        And also this is caused already by class definition:
        The scrollbars come from the QAbstractScrollArea and the header view comes from the specific item view. So they are more or less unrelated.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        J 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @tokafr
          i think you wont be successful this way. Since the item view widget just layouts it's widgets (viewport, scrollbars, headerviews, ...) this way. And this happens on every resize and on some other actions.
          And this is hidden in the private part of the item view widget.

          And also this is caused already by class definition:
          The scrollbars come from the QAbstractScrollArea and the header view comes from the specific item view. So they are more or less unrelated.

          J Offline
          J Offline
          Jan-Willem
          wrote on last edited by
          #4

          @raven-worx: while I'm not sure it is the right solution for what @tokafr wants to do, he can take ownership of the vertical scrollbar and have some influence this way. I have done it before that way.

          @tokafr: Instead of trying to influence the hidden layout of the QTableView, you could mask the space between the header view and the vertical scrollbar to make it look like it being part of the header view. Stylesheets are probably the best place to try.

          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