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



  • 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!


  • Lifetime Qt Champion

    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 ?



  • 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



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



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



  • 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);
    }@


  • Lifetime Qt Champion

    Your if is looking strangeā€¦

    Could you explain why it's coded that way ?

    As a side note, why note use isVisible ?



  • 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!


  • Lifetime Qt Champion

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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.