Results 1 to 6 of 6

Thread: QLineEdit persistent selection

  1. #1
    Join Date
    Sep 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QLineEdit persistent selection

    I would like to have persistent selection in QLineEdit. This means if I i.e. I will switch to other widget (edition ended, QLineEdit has lost focus) selection remains.
    I tried to get this behaviour by acting on editingFinished() signal, which works, but only to some extent.
    There is problem with hiding window. If I switch to another window and then I'll go back to window with my QLineEdit with selection then selection is lost.

  2. #2
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QLineEdit persistent selection


  3. #3
    Join Date
    Sep 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit persistent selection

    Could you elaborate?
    I can't think of any way this method could solve my problem.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLineEdit persistent selection

    Check in Qt's source code if anything happens on the focusInEvent for the line edit. Also mousePressEvent is worth checking out. Maybe you can prevent the action somehow by intercepting the event.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QLineEdit persistent selection

    My bad I misunderstood your problem.

    What do you need that persistent selection for ?

    What you're trying to achieve is not a standard "line edit" behavior.

    You might consider subclassing QLineEdit and alter the focus events + paint event.

  6. #6
    Join Date
    Sep 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit persistent selection

    Quote Originally Posted by bunjee View Post
    What do you need that persistent selection for ?
    I'm making a form for QBE with text completion (as for now it will only be a prefix search).
    I have a data model inheriting from QAbstractTableModel with (actually not yet, but will be) relational data in it. And I want to give the user possibility to write only the beginnings of name, surename, city, order number etc. and then to auto-complete the rest of fields.

    As this is the first time I'm trying to write something in Qt after some looking around the classes I thought that QTableView will be something I should go for, so I tried QItemDelegate to create persistent aditors in a nice grid. And there problems began:
    - as I mentioned in the first post I couldn't get to keep the selection as I wanted
    - when I set the input of fields it generated filter on data which returned 0 rows and I couldn't traverse through all fields with tab anymore
    - also there was problem as I couldn't leave the grid using tab (it cycles through all cells on the grid, but does not leave the table widget)

    So after some thinking and looking at my code I thought that I wrote much more code (handling data change in model, creating and monitoring editors) to force QTableView to act as I want then use the features of QTableView.
    So I switched to QTableWidget. I just set it to have one row and never change it (this solves problem with 0 rows in data model). Set widgets of all cells to class inheriting from QLineEdit and wrote code to take care of data changes in data model.
    And that solved my problem with "dissappearing" selection. It seems like QTableView does something more than just call QItemDelegate::setEditorData() when data in the model is changed.
    Also the problem with the tab traversal inside the table was solved with this change.
    And only thing I see now that I have to deal with is making the tab traversal not getting stuck inside the QTableWidget.

Similar Threads

  1. Replies: 5
    Last Post: 8th June 2009, 22:16
  2. Replies: 10
    Last Post: 12th February 2009, 07:23
  3. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 15:13
  4. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25
  5. selection in QLineEdit
    By spigel in forum Qt Programming
    Replies: 10
    Last Post: 17th May 2007, 09:43

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.