Solved Need a suggestion for displaying song information
-
@jsulm I have already tried that using the
QListWidget
. Problem there was that 1500 songs were scanned in 500ms and I emitted a signal for each one of them. As a result of that the UI updated at once (and got blocked) instead of inserting the songs one by one. But I will try again with theQTableWidget
. Thank you. -
I'm still a bit perplexed, 1500 data points is not a lot, it should work seamlessly.
Can we try one thing? remove the delegate and just store the song title in the first column as a string in
Qt::EditRole
and nothing else, see if that works faster -
I am doing the following now (without delegate)
void MusicLibrary::loadAudios(Audios audios) { clear(); setRowCount(audios.size()); setColumnCount(1); setUpdatesEnabled(false); for (int i = 0; i < audios.size(); i++) { QTableWidgetItem *item = new QTableWidgetItem; item->setData(Qt::EditRole, audios[i]->title()); setItem(i, 0, item); } setUpdatesEnabled(true); }
It's not slow but it's not seemless either. Not sure if it helps but those are the changes I made to the
QTableWidget
.setAlternatingRowColors(true); setEditTriggers(QAbstractItemView::NoEditTriggers); setFocusPolicy(Qt::NoFocus); setFrameStyle(QFrame::NoFrame); //setItemDelegate(new RowHoverDelegate(this, this)); setSelectionMode(QAbstractItemView::NoSelection); setShowGrid(false); setStyleSheet(loadStyleSheet()); setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); setWordWrap(false); horizontalHeader()->hide(); horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); horizontalScrollBar()->hide(); verticalHeader()->hide();
-
@jsmolka You could emit a signal for a set of songs, lets say for 10.
-
@jsulm said in Need a suggestion for displaying song information:
@jsmolka You could emit a signal for a set of songs, lets say for 10.
Mmh, correct me if I'm wrong here, but, as long as the loop is going on, the Repaint event is postponed until the next time the event loop ist processed 🤔
The op would need to do something like calling
processEvents()
to update the ui. QThread is not an option, as QTableWidgetItem is a gui element and therefore may only be processed in the main thread!? -
@J.Hilk I suggested to use an extra thread for music file scanning. From this thread he is emitting a signal with music data which is then handled in the GUI thread. His problem is now that he is emitting the signal for each song and thus flooding the GUI thread. That's why I suggested to group the song data to not to emit too many signals. I did NOT suggest to use GUI related classes in other threads than GUI thread. If he is using such classes in this second thread then it is clearly wrong (I did not check his code that thoroughly).
-
Perhaps you could use Qt Concurrent, specially if you want to add a sugar progress to the process. https://doc.qt.io/qt-5.10/qtconcurrent-index.html
I don't think you need to create a worker thread class just to make this simple thing as you already have the Qt Concurrent to do that for you in a simply way. You can even, pause/continue and stop the process with it.
-
Thanks for all your suggestion. With a seperate thread for loading and the
QTableWidget
instead ofQListWidget
all runs smoothly.Just another question out of curiosity. If I create a
QTableWidgetItem
on the heap, do I have to delete it manually? Because there is no parent property unlike in most of Qt's classes. -
@jsmolka I don't think that you need to delete it manually as the widget will take the ownership of the item.
-
@Mr-Gisa is correct.
http://doc.qt.io/qt-5/qtablewidget.html#setItem
The table takes ownership of the item