Results 1 to 4 of 4

Thread: How to get cusor position and selection in QListWidget present editor

  1. #1
    Join Date
    Jun 2011
    Posts
    4
    Qt products
    Platforms
    Windows

    Default How to get cusor position and selection in QListWidget present editor

    Hi, im relatively new to Qt, and I am using pyqt.

    What I want to be able to do is to allow the user to enter data in to a QListWidget by typing. The user will type a sentence, and a list item will be created for each word.

    What I have got so far, is a QListWidget set to display vertically, the user clicks on to the first and only QListWidgetItem which has "type here" in it. Clicking and typing opens the persistent editor. I use onKeyRelease to detect if the user has pressed space, and create a new QListWidgetItem. I then set this item as the selected item, so when they continue to type the text is now being entered in to the new QListWidgetItem.

    What I want to do, and am having problems figuring out, is the following:
    When the user presses delete, if the cursor is at the end of the persistent editor, and no text is selected, then I want to open the persistent editor on the next QListWidgetItem.
    Similarly, if the user presses backspace, and the cursor is at the beginning of the persistent editor, and no text is selected, then the previous item is selected, the persistent editor opened, and the cursor moved to the end.

    Is this do-able?
    Any help, not just in pyqt, very much appreciated!

    Phill

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: How to get cusor position and selection in QListWidget present editor

    You can try to set item delegate. Subclass QItemDelegate or QStyledItemDelegate and override createEditor, so you can use your own editor with all the necessary functionality.

  3. #3
    Join Date
    Jun 2011
    Posts
    4
    Qt products
    Platforms
    Windows

    Default Re: How to get cusor position and selection in QListWidget present editor

    Thats enough to get me Googleing so if I do something like: http://python.6.n6.nabble.com/QItemD...td1798113.html then I could use QLineEdit instead of the standard editor, and then I would get access to app its methods?

    How would I reference it? Using something like QListWidget.QListWidgetItem.QLineEdit ?

    I also read somewhere this could use quite a bit of memory if I have 10 or more QListWidgetItem's

    Phill

  4. #4
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: How to get cusor position and selection in QListWidget present editor

    Take a look at stardelegate sample. createEditor method returns a pointer to the editor widget. When you override it, you can use any widget you like, e.g. QLineEdit. Editor instance is created in createEditor method, there you connect editor's editingFinished signal to some slot in your delegate where you process it. Most likely you will need to override setEditorData and setModelData also.

Similar Threads

  1. QListWidget scrollbar position
    By papillon in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2011, 23:44
  2. Handle ESC button in persistent editor in qlistwidget
    By sanket.mehta in forum Qt Programming
    Replies: 0
    Last Post: 15th November 2010, 07:30
  3. QLabel selection: start and end position?
    By truefusion in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2009, 02:00
  4. Column Selection Text Editor
    By zyxue in forum Qt Programming
    Replies: 1
    Last Post: 20th June 2007, 08:28
  5. QListWidget selection behavior
    By Arthur in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2006, 14:10

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
  •  
Qt is a trademark of The Qt Company.