Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Disable scroll area in QTableView/QTableWidget

    General and Desktop
    qtableview scroll scrollarea qscrollarea viewport
    2
    4
    5299
    Loading More Posts
    • 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
      Maluna34 last edited by Maluna34

      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 Reply Quote 0
      • VRonin
        VRonin last edited by

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

        table->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);

        1 Reply Last reply Reply Quote 2
        • M
          Maluna34 last edited by

          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);
          
          VRonin 1 Reply Last reply Reply Quote 0
          • VRonin
            VRonin @Maluna34 last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • First post
              Last post