I don't see a selection bar in the QListWidget when a QT dialog opens
-
Hi all,
I am working on an old, hand crafted piece of code of another programmer and have run out of ideas.
Because it's huge, I cannot include it here.My problem is with a dialog containing a QListWidget which contains i.e. 5 lines of text.
On first opening I see the texts, but no line shows the selection bar.
I would expect the first line to show this gray bar.
When I now click on a line, the gray selection bar is visible.This is what I tried out to no avail (all compile ok, but take no effect):
ui->grooveList->setCurrentItem(0);
item = ui->grooveList->takeItem(0); ui->grooveList->setCurrentItem(item); item->setSelected(true);
ui->grooveList->setItemSelected(item);
ui->grooveList->setItemSelected(item, true);
ui->grooveList->setCurrentRow(index);Has anyone an idea, why there is no initial selection bar?
On the other hand, I have tried to write a simple executable showing a dialog with only QListWidget and it works. I see the selection bar!
I seem not to have understood how the principal mechanism works... -
@MLandgraf
I don't know, but in order to see a selection bar does the list widget have to have the focus? Clicking into it would give it focus, so that might be why it showed up. It may be that the first widget on the dialog starts with the selection. Or maybe one of a dialog's buttons has the focus initially. I believe you can set the desired widget to have the focus if this is required. -
Also make sure to set the selection after you filled the QListWidget.
-
I am pretty sure the widget is refilled later on or the selection is cleared. Simplify the widget until it works as expected.