I have a large qtablewidget. Let's say 200 rows. In QListWidget, there is setMaxVisibleItems(30), which is extremely useful. What's the equivalent for a qtablewidget, except for rows. Ie. setMaxVisibleRows?
I considered setting a max height for my window. However, this application can be used on varying DPIs. So, it may be small for some. Plus, that felt like a needless restriction.
I also saw this: How to show only 30 rows and hide the remaining rows of QTableWidget
However, it isn't the same by any means.
Thank you very much in advanced!
The best way I would do it is to use Qt's void QTableView::setRowHidden(int row, bool hide)
void QTableView::setRowHidden(int row, bool hide):
If hide is true row will be hidden, otherwise it will be shown.
If you know the count of your table you can use that othewise you will have to use a model
and use rowCount()
.
Then the for
loop should be easy:
for(int i = startHidingHere; i < numOfRows; i++)
myTable->setRowHidden(i, true);
You can obviously do a similar method to un-hide them. This method also works great for filters if needed in the future.
Other possible useful methods:
bool QTableView::isRowHidden(int row);
void QTableView::setColumnHidden(int column, bool hide);
void QTableView::setModel(QAbstractItemModel *model);
-> int QAbstractItemModel::rowCount(const QModelIndex & parent = QModelIndex()) const
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.