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. Disable scroll area in QTableView/QTableWidget
QtWS25 Last Chance

Disable scroll area in QTableView/QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtableviewscrollscrollareaqscrollareaviewport
5 Posts 3 Posters 7.6k 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.
  • M Offline
    M Offline
    Maluna34
    wrote on 14 Jan 2019, 07:32 last edited by Maluna34
    #1

    Hi,

    I currently have a QTableWidget into a QScrollArea and I would like to trigger the scrollbar of my scroll area when it's needed instead of the one on the TableView.
    I managed to disable the scrollbar of the TableView but the other one is not triggered.

        auto *scroll = new QScrollArea;
        auto *scrollWidget = new QWidget;
        auto *gridLayout = new QGridLayout(scrollWidget);
    
        auto *table = new QTableWidget;
    
        table->setRowCount(3);
        table->setColumnCount(4);
    
        // Disable scroll bar of the table
        table->horizontalScrollBar()->setDisabled(true);
        table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    
        gridLayout->addWidget(table);
    
        scroll->setWidget(scrollWidget);
        scroll->setWidgetResizable(true);
        scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    

    I think it's about the viewport of the TableView. Maybe the idea is to have the viewport adjusted to the content.
    Thanks for your help.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 14 Jan 2019, 08:10 last edited by
      #2

      http://doc.qt.io/qt-5/qabstractscrollarea.html#sizeAdjustPolicy-prop

      table->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);

      1 Reply Last reply
      2
      • M Offline
        M Offline
        Maluna34
        wrote on 14 Jan 2019, 08:37 last edited by
        #3

        Unfortunately it seems that it's not enough to trigger the scrollbar of the parent.
        The solution I found is to set the fixedWidth of the table like this :

        int size{ 0 };
        for (int i = 0; i < table->columnCount(); ++i)
        	size += table->columnWidth(i);
        
        table->setFixedWidth(size);
        
        V 1 Reply Last reply 14 Jan 2019, 08:46
        0
        • M Maluna34
          14 Jan 2019, 08:37

          Unfortunately it seems that it's not enough to trigger the scrollbar of the parent.
          The solution I found is to set the fixedWidth of the table like this :

          int size{ 0 };
          for (int i = 0; i < table->columnCount(); ++i)
          	size += table->columnWidth(i);
          
          table->setFixedWidth(size);
          
          V Offline
          V Offline
          VRonin
          wrote on 14 Jan 2019, 08:46 last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • T Offline
            T Offline
            tdosov
            wrote on 7 May 2024, 09:20 last edited by
            #5
            table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
             table->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
            setMinimumWidth(table->sizeHint().width());
            
            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