A
A
Artem Filimonov2018-06-29 08:13:36
Qt
Artem Filimonov, 2018-06-29 08:13:36

How to get the number of records that fit in a QTableView window?

it is necessary to find kol-in records which are visible to the user.
the only thing that comes to mind is to find the height of the table and divide by the height of the row...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2018-06-29
@Nvek

This is actually a difficult task, and I solved it like this.

QHeaderView* header = ui->tableView->verticalHeader();
QWidget* viewport = header->viewport();
int i1 = header->logicalIndexAt(0);
int i2 = header->logicalIndexAt(viewport->height() - 1);
if (i2 < 0)
    i2 = header->count() - 1;
QString s = QString::number(i1) + " - " + QString::number(i2);
ui->lbResult->setText(s);

If in a very simplified form, then a little not so.
return m_tableView->viewport()->height() / m_tableView->rowHeight(0);

A
Artem Filimonov, 2018-06-29
@Nvek

Here is the answer:

return m_tableView->height() / m_tableView->rowHeight(0) - 1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question