Results 1 to 2 of 2

Thread: QListView: keyboard navigation doesn't wrap when Wrapping is enabled

  1. #1
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QListView: keyboard navigation doesn't wrap when Wrapping is enabled

    Summary: with wrapping enabled in a QListView, if the cursor is at an edge of the list, keyboard navigation toward that edge does nothing.

    Here's a wordier but more thorough description:

    In TopToBottom flow mode with wrapping enabled, when the cursor is at the bottom of a column, hitting down doesn't navigate to the top of the next column. Similarly, when at the top of a column, hitting up doesn't navigate to the bottom of the previous column.

    In LeftToRight flow mode with wrapping enabled, when the cursor is at the right edge of a row, hitting right doesn't navigate to the left edge of the next row. Similarly, when at the left edge of a row, hitting left doesn't navigate to the right edge of the previous row.

    (Note that when I use the terms "row" and "column", these are sort of pseudo terms. With wrapping turned on, they look like rows and columns, but of course the list model itself is nothing but rows.)

    I've looked around for any mention of this. All I found were these two separate posts, both with no responses:
    http://www.qtcentre.org/threads/2168...w-keyboard-nav
    http://www.qtcentre.org/threads/3501...pping-property

    I'm using the stock Qt 4.7.0 with PyQt 4.7.4 from the Ubuntu 10.10 64-bit repos. Here's a minimal python program that demonstrates this behaviour:

    Qt Code:
    1. import sys
    2. from PyQt4 import QtCore, QtGui
    3. from PyQt4.QtCore import Qt
    4.  
    5. class TestWindow(QtGui.QMainWindow):
    6. def __init__(self):
    7. QtGui.QMainWindow.__init__(self)
    8. self.list = TestListView(self)
    9. self.setCentralWidget(self.list)
    10. self.resize(500, 500)
    11.  
    12. class TestListView(QtGui.QListView):
    13. def __init__(self, parent):
    14. QtGui.QListView.__init__(self, parent)
    15. self.setModel(TestListModel(parent))
    16. self.setUniformItemSizes(True) # speeds up listview
    17. self.setFlow(QtGui.QListView.LeftToRight) # default is TopToBottom
    18. self.setWrapping(True) # default is False
    19.  
    20. class TestListModel(QtCore.QAbstractListModel):
    21. def __init__(self, parent):
    22. QtCore.QAbstractListModel.__init__(self, parent)
    23.  
    24. def rowCount(self, parent=None):
    25. return 1000
    26.  
    27. def data(self, index, role=Qt.DisplayRole):
    28. if role == Qt.DisplayRole and index.isValid():
    29. return index.row()
    30.  
    31. if __name__ == '__main__':
    32. app = QtGui.QApplication(sys.argv)
    33. win = TestWindow()
    34. win.show()
    35. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    I'd argue that this behaviour is unexpected. Compact view and icon view in any file manager I've ever used wraps the cursor if it reaches an edge and if there's logically somewhere for it to go next. This makes the most of keyboard navigation.

    Might this be considered a bug, or an unimplemented feature? Anyone know of any workarounds? The use case that I personally care about is LeftToRight flow mode with Wrapping enabled. I tried overriding QListView.KeyPressEvent() for left and right keys, like this:

    Qt Code:
    1. def keyPressEvent(self, event):
    2. if event.key() == Qt.Key_Left:
    3. self.setCurrentIndex(self.moveCursor(self.MovePrevious, event.modifiers()))
    4. elif event.key() == Qt.Key_Right:
    5. self.setCurrentIndex(self.moveCursor(self.MoveNext, event.modifiers()))
    6. else:
    7. QtGui.QListView.keyPressEvent(self, event) # handle it as usual
    To copy to clipboard, switch view to plain text mode 

    but that just moves the cursor up and down, not left and right. Using MoveLeft and MoveRight does what it says, but again doesn't wrap around the left or right edge, which is my original problem. Looking at the code in http://qt.gitorious.org/qt/qt/blobs/.../qlistview.cpp, "case MovePrevious" and "case MoveNext" are both empty in QListView::moveCursor. They both precede "case MoveUp" and "case MoveDown", which I presume in C++ means that's what they default to.

    Thanks for any suggestions,

    Martin

  2. #2
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListView: keyboard navigation doesn't wrap when Wrapping is enabled

    Bump. Can anyone confirm if this problem still exists in the most recent release (or even the latest git commit) of Qt?

Similar Threads

  1. Navigation by QListView with enabled isWrapping property
    By qt-closer in forum Qt Programming
    Replies: 0
    Last Post: 12th October 2010, 21:04
  2. TreeView keyboard navigation
    By Onanymous in forum Newbie
    Replies: 2
    Last Post: 14th May 2010, 06:22
  3. QListView keyboard nav
    By jej in forum Newbie
    Replies: 0
    Last Post: 11th June 2009, 09:18
  4. Word wrap in QListView
    By jiveaxe in forum Qt Programming
    Replies: 33
    Last Post: 1st September 2007, 21:06
  5. QListView word wrap
    By serega in forum Qt Programming
    Replies: 17
    Last Post: 30th August 2007, 03:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.