Not on an item in QListWidget
-
Above a QListWidget I must display an index number of the item in the list. I am able to accomplish this using
connect ( ui->aoList, &QListWidget::itemEntered, this, &NotebookView::OnMouse );
and using the following to display the index:
void Common::AO_MouseHover ( QListWidgetItem* item ) { // Show the display index m_pGlobal->ao_data.dspIndex->show (); // Get the index of the item selected int32_t row = m_pGlobal->ao_data.list->row ( item ); // Convert the integer to string QString idx = QString::number ( row + 1 ); // Set the index value m_pGlobal->ao_data.dspIndex->setText ( "# " + idx ); }
This works great but when I am in the QListWidget and not on an item, I need the display index to disappear. I can't use itemEntered because it only triggers when on an item. Any Ideas?
-
@gabello306 said in Not on an item in QListWidget:
when I am in the QListWidget and not on an item, I need the display index to disappear
When you don't hover any item how should the widget know what index to display?
Don't really understand what you are trying but maybe using an event filter for yourQListWidget
helps -
Why not use the item model to do it?
#include <QApplication> #include <QListWidget> int main(int argc, char **argv) { QApplication app(argc, argv); QListWidget list; for (int row = 0; row < 10; ++row) { QListWidgetItem *item = new QListWidgetItem(QString("Example %1").arg(row), &list); item->setData(Qt::ToolTipRole, QString("Row %1").arg(row)); list.addItem(item); } list.resize(200, 600); list.show(); return app.exec(); }
-
@gabello306
@ChrisW67's suggestion is indeed the simplest if you are willing to assign static tooltips to existing items in the list, and recommended if that is the case. However it will require some further work if you insert, delete or move items in your list. Do you need that, or is the list fixed? It also displays the information as a popup tooltip over each item rather than your original requested "Above a QListWidget I must display an index number" so depends whether you mind about that.