Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. I don't see a selection bar in the QListWidget when a QT dialog opens

I don't see a selection bar in the QListWidget when a QT dialog opens

Scheduled Pinned Locked Moved Solved Qt 6
6 Posts 3 Posters 240 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MLandgraf
    wrote on 19 Feb 2025, 12:44 last edited by
    #1

    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...

    J 1 Reply Last reply 19 Feb 2025, 13:13
    0
    • M MLandgraf
      19 Feb 2025, 12:44

      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...

      J Offline
      J Offline
      JonB
      wrote on 19 Feb 2025, 13:13 last edited by
      #2

      @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.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 19 Feb 2025, 13:49 last edited by
        #3

        Also make sure to set the selection after you filled the QListWidget.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MLandgraf
          wrote on 19 Feb 2025, 13:54 last edited by MLandgraf
          #4

          Thank you.

          I tried both; focus has no effect and QListWidget is filled in the very beginning, prior to my attempts to make the bar visible.
          Any other idea?
          Or do I have to connect to some signal in order to make it visible?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 19 Feb 2025, 13:55 last edited by
            #5

            I am pretty sure the widget is refilled later on or the selection is cleared. Simplify the widget until it works as expected.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • M Offline
              M Offline
              MLandgraf
              wrote on 6 Mar 2025, 10:33 last edited by
              #6

              This was the solution, to set currentRow() (provided there is any groove data):
              if((ui->grooveList->currentRow() < 0) && (ui->grooveList->count() > 0)){
              ui->grooveList->setCurrentRow(0);
              }

              1 Reply Last reply
              0
              • M MLandgraf has marked this topic as solved on 6 Mar 2025, 10:34

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved