Disable scroll area in QTableView/QTableWidget
Unsolved
General and Desktop
-
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. -
http://doc.qt.io/qt-5/qabstractscrollarea.html#sizeAdjustPolicy-prop
table->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
-
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);