cplusplusqt | Unsorted

Telegram-канал cplusplusqt - C++ & Qt

1137

Link: @CplusplusQt Embedded: @EMBCpp • No DM without prior permission • Behave friendly • No NSFW • No Spam • No unauthorized Bots • Don't advertise other groups

Subscribe to a channel

C++ & Qt

and damn right it is faster

Читать полностью…

C++ & Qt

perhaps it doesn't have to be perfect either? Skipping some lines when resizing isn't that much of a problem perhaps?

Читать полностью…

C++ & Qt

also wondering what will happen if i will just be getting element in the vierwport and calling the resizeRowToContents

Читать полностью…

C++ & Qt

or only on visible elements

Читать полностью…

C++ & Qt

resizeToContents on first 3 columns also make gui thread go up to 100% but without visible lag. this could be made fixed size thats all

Читать полностью…

C++ & Qt

so if i set all resize policies to fixed without word wrap and the 4th column to stretch(cant see full mesage) or interactive(this could work but word wrap + stretch would be beter), i get decent performance

if on to of previous i do word wrap, nothing is changing because the row height is fixed, but if i enable resizeToContents on the vertical header i get huuuge performance penalty

Читать полностью…

C++ & Qt

god damn there is no valgrind on mac arm yet, constant pain in the butt, i have to use pc for this purposes

Читать полностью…

C++ & Qt

so this behave same on my air m2. scroll is takin 2-3% of cpu is short bursts (idk seems ok), resize with mouse eats up entire gui thread/core to 100%

Читать полностью…

C++ & Qt

Also the below calls are very expensive and should be aboided if used.

resizeColumnsToContents() / resizeRowsToContents()

Читать полностью…

C++ & Qt

I have done similar things with tables in qml. Apparently qml uses single point precision for row offsets, so if the number of rows are big enough the layout gets weird (even if the performance is good)

Читать полностью…

C++ & Qt

You can also do that in the parent widget by using only x rows in the listview.

Читать полностью…

C++ & Qt

Uniform row heights is also good, but I suppose you want it to look as in the image above

Читать полностью…

C++ & Qt

Are you using, by any chance, any call to view->setIndexWidget()? This implies a huge performance penalty. Also, if you can move to QML, it reuses delegates and has no calls to paint(), which is quite likely to be executed in CPU instead of GPU.

Читать полностью…

C++ & Qt

no I did not. i guess the table resize entire table at once. if i will manage to run profiler i will get back to you

Читать полностью…

C++ & Qt

l have change resizeToContents and Stretch to FIxed and yes it is fast alright

Читать полностью…

C++ & Qt

so i managed to make this


log_view::log_view(log_model* lm)
: QTableView(nullptr) {
setModel(lm);
setAlternatingRowColors(true);
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setWordWrap(true);

verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
verticalHeader()->setDefaultSectionSize(24);

auto header = horizontalHeader();
// i gave up on dynamic columns, just eyeballed the default size and let the
// user change it god damn
header->setSectionResizeMode(0, QHeaderView::Interactive);
header->resizeSection(0, 140);
header->setSectionResizeMode(1, QHeaderView::Interactive);
header->resizeSection(1, 80);
header->setSectionResizeMode(2, QHeaderView::Interactive);
header->resizeSection(2, 73);
header->setSectionResizeMode(3, QHeaderView::Stretch);

connect(
header, &QHeaderView::sectionResized,
this, &log_view::on_section_resized
);

connect(
verticalScrollBar(), &QScrollBar::valueChanged,
this, &log_view::schedule_visible_row_resize
);

connect(
model(), &QAbstractItemModel::dataChanged, this,
[this](const QModelIndex& topLeft, const QModelIndex& bottomRight) {
if (topLeft.column() == 3) {
for (int r = topLeft.row(); r <= bottomRight.row(); ++r)
if (visualRect(model()->index(r, 0)).intersects(viewport()->rect()))
resizeRowToContents(r);
}
}
);

QMetaObject::invokeMethod(this, &log_view::schedule_visible_row_resize, Qt::QueuedConnection);
}

void log_view::on_section_resized(int logicalIndex, int oldSize, int newSize) {
if (logicalIndex == 3)
schedule_visible_row_resize();
}

void log_view::schedule_visible_row_resize() {
QMetaObject::invokeMethod(
this, &log_view::update_visible_row_heights,
Qt::QueuedConnection
);
}

void log_view::update_visible_row_heights() {
if (!model() || model()->rowCount() == 0)
return;

setUpdatesEnabled(false);

const int first = rowAt(0);
if (first < 0) {
setUpdatesEnabled(true);
return;
}

int last = rowAt(viewport()->height() - 1);
if (last < 0)
last = model()->rowCount() - 1;

for (int row = first; row <= last; ++row)
resizeRowToContents(row);

setUpdatesEnabled(true);
}

void log_view::resizeEvent(QResizeEvent* ev) {
setUpdatesEnabled(false); // importand to not let the table view do nothin by itlself
QTableView::resizeEvent(ev);
setUpdatesEnabled(true);
schedule_visible_row_resize();
}


the schedule_visible_row_resize was suggusted by grok, the part that makes invocation in queued fashion, as he says:
Qt’s standard “do it once, later” pattern

When the current event loop finishes processing all the resize/scroll/paint events that are already queued, then run this once

Читать полностью…

C++ & Qt

but the scrollbar wont cbe in correct scale

Читать полностью…

C++ & Qt

it has to look at all elements above at least (and perhaps the rest of them to get the scrollbar size right)

Читать полностью…

C++ & Qt

With dynamic row height it has to do that i suppose, but perhaps it could happen less often

Читать полностью…

C++ & Qt

i wonder as if the widget tries to recalculate all the heights, maybe this could be optimized to only update visible elements somehow

Читать полностью…

C++ & Qt

not as bad as this though

Читать полностью…

C++ & Qt

this defenitetly helps with performance with 200 elements. but with 10k it is not enough

Читать полностью…

C++ & Qt

@Dolfost i tried this and it doesn't feel that slow on my machine:

QStandardItemModel* lm = new QStandardItemModel();
lm->setColumnCount(4);

for(int i = 0; i < 2000; ++i)
{
QList<QStandardItem*> row;

row << new QStandardItem(QString::number(i)) << new QStandardItem("A") << new QStandardItem("B");
if(i % 20 == 0)
row << new QStandardItem("CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC CCCCCCCCCC ");
else
row << new QStandardItem("C");

lm->appendRow(row);
}

ui->log_view->setModel(lm);
ui->log_view->setAlternatingRowColors(true);
ui->log_view->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
ui->log_view->setSelectionBehavior(QAbstractItemView::SelectionBehavior::SelectRows);
ui->log_view->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::ResizeToContents);

auto header = ui->log_view->horizontalHeader();

header->setSectionResizeMode(0, QHeaderView::ResizeMode::ResizeToContents);
header->setSectionResizeMode(1, QHeaderView::ResizeMode::ResizeToContents);
header->setSectionResizeMode(2, QHeaderView::ResizeMode::ResizeToContents);

header->setSectionResizeMode(3, QHeaderView::ResizeMode::Stretch);
ui->log_view->setWordWrap(true);
connect(header, &QHeaderView::sectionResized, this,
[this](int logicalIndex, int /*oldSize*/, int /*newSize*/) {
if (logicalIndex == 3)
ui->log_view->resizeRowsToContents();
}
);

Читать полностью…

C++ & Qt

It's been quite a long since I used widgets. I can suggest the below solution.

Try disable updates while resizing.

Qt repaints continuously during a resize event. You can suppress this.

Override resizeEvent.

void MyWidget::resizeEvent(QResizeEvent *event)
{
tableWidget->setUpdatesEnabled(false);
QWidget::resizeEvent(event);
tableWidget->setUpdatesEnabled(true);
}

Читать полностью…

C++ & Qt

In one of my projects, I have a thumbnail view that with about 100k pictures. Performance was really bad - in the end, I just implemented the paintEvent() myself. It's really nice now.

Читать полностью…

C++ & Qt

I'd probably subclass the list widget and only render the visible portion of the list.

Читать полностью…

C++ & Qt

200 rows should work even without models I think

Читать полностью…

C++ & Qt

I think there may be ways to make the size estimation faster

Читать полностью…

C++ & Qt

Did you try running callgrind (or any other profiler) to reveal where the bootleneck is in?

Читать полностью…

C++ & Qt

Is it faster if all columns have fixed with?

Читать полностью…
Subscribe to a channel