Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListWidget: blank line appears during runtime and "selection shifts"
Qt 6.11 is out! See what's new in the release blog

QListWidget: blank line appears during runtime and "selection shifts"

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 2.9k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    Irispalida
    wrote on last edited by
    #1

    Hi,
    I have QListWidget populated with custom items - each contains some labels.
    From time to time "blank item" suddenly appears on top of list, other items move one position down and selection "shifts one line" - when you click on first row it highlights, but selected is index you clicked + number of blank items.
    In fact it seems like items are "physically" in place, but their graphical representation shifts down.
    When you drag&drop any item to the blank space, all blank line disappear and everything is alright for a while.

    Thanks in advance for any suggestions!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Do you have a minimal example where you can reproduce this behavior ?

      Also, what version of Qt are you using ? On which OS ? And how did you installed Qt ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Irispalida
        wrote on last edited by
        #3

        Hi and thanks for really quick reply!

        Unfortunately I'm not able to reproduce this behavior at all. It just happens from time to time. Didn't discover any relation with any action in GUI of my application.
        I hoped that someone has encountered similar behavior - that was the point of the question.

        edit: The behavior appears only when there are enough items to scroll.

        Sorry for not posting my configuration:
        Qt 5.1.1 installed from .run file from qt-project.org
        Ubuntu 13.10

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NicuPopescu
          wrote on last edited by
          #4

          @
          ...
          ui->listWidget->setDragEnabled(true);
          ui->listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
          ui->listWidget->setDropIndicatorShown(true);
          ui->listWidget->setMovement(QListView::Static);
          ui->listWidget->setAcceptDrops(true);
          ui->listWidget->setDragDropMode(QAbstractItemView::InternalMove);
          ...
          @
          setMovement() does the trick ... see where is called, before setAcceptDrops(), or set it in designer, otherwise it does not work

          hope it helps!

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Irispalida
            wrote on last edited by
            #5

            Thanks for your post, I'll try that and after while of testing give here a note whether it helped.

            edit: Actually it didn't work, setMovement() is just about stitching items to grid or not and it's by default static. This offset - it's the best expression for that - seems to not depend on user actions, it just appears not touching anything...

            1 Reply Last reply
            0
            • I Offline
              I Offline
              Irispalida
              wrote on last edited by
              #6

              Have an update, as usually it was just poor observation skills :-). The reason of this growing offset is as follows:
              There is a collection of QListWidgets (playlists) in QStackedWidget and as its played, I scroll through them using:
              @QListWidget::scrollToItem(item);@
              And this apply whether or not the QListWidget is the current widget of QStackedWidget - in other words when it is or isn't wisible And that's the trouble causing offset.
              The solution is:
              @if(stackedWidget.currentWidget == this) {
              listWidget.scrollToItem(item);
              }@

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Your if is looking strange…

                Could you explain why it's coded that way ?

                As a side note, why note use isVisible ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  Irispalida
                  wrote on last edited by
                  #8

                  I'm not completely sure, what you mean by strange, but it is just for illustration. In my application I'm doing it bit more complicated because these "playlists" has Id's.
                  Anyway, isVisible suits this purpose perfect - didn't know about this function so far.

                  Thanks!

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @if(stackedWidget.currentWidget == this) {
                    listWidget.scrollToItem(item);
                    }@

                    doesn't make sense to me. A QStackedWidget is a component from a higher level widget that contains a set of widget that you want to manage so testing it against "this" is very strange to me.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      Irispalida
                      wrote on last edited by
                      #10

                      Ok, I've tested it while ago and it's working pretty fine.
                      "this" is in this case widget managed by the QStackedWidget.

                      But I admit, that use of "isVisible" method is better, because you don't have to pass the reference of QStackedWidget to widgets managed by it.

                      1 Reply Last reply
                      0

                      • Login

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