Results 1 to 9 of 9

Thread: QCompleter - isslplpue

  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QCompleter - isslplpue

    Hello forum,

    I am sure that some one over here have used QCompleter somewhere in their project and i need you help. The manual says something related to file system.

    How to customize it if it a customized item model derived from QAbstractItemModel ?

    I have a tree model preety much same as the simple tree model example. A snapshot might help:

    tree.jpg


    I want the completer to provide the user the look-up hint in such a manner that if the user type X3D, then all the names that starts with "X3D...." pop up in the lookup completion hint.

    I think in that we have to lookup all the levels at a time. What do you think? I already did the following changes, but i am not getting what i need and i believe i am far away from what i want to get.

    Qt Code:
    1. QCompleter *completer = new QCompleter(this);
    2. completer->setModel(m_h3dTreeModel);
    3. m_nodeHighlightingEditor->setCompleter(completer);
    To copy to clipboard, switch view to plain text mode 



    I need more hints to achieve this behavior.

    Let me know if i am clear enough with my requirement explanation.


    Regards
    Sajjad

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QCompleter - isslplpue

    Have you read: Handling Tree Models?

  3. #3
    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: QCompleter - isslplpue

    Create a proxy model that will "flatten" your tree model. Then assign that proxy model to your completer.
    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.


  4. #4
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QCompleter - isslplpue

    Hi

    I did not actually get what do you mean by flattening the model. Does it happen by itself once i assign the source model to the proxy model or i have re-program it and break the hierarchy while building the proxy model.


    Looking forward to more on this !!


    Regards
    Sajjad

  5. #5
    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: QCompleter - isslplpue

    No, nothing happens by itself. By flattening I mean that the proxy model needs to transform the original model in such a way that all children of each item become siblings of that item so that you don't have children anymore and all elements are directly under the root of the model.
    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.


  6. #6
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QCompleter - isslplpue

    Hi

    I think that in this case i have subclass the QProxyModel and over-ride the following functions as follows:

    Qt Code:
    1. class FlatTreeModel : public QAbstractProxyModel
    2. {
    3. public:
    4. QModelIndex mapFromSource(...);
    5. QModelIndex mapToSource(....);
    6.  
    7. };
    To copy to clipboard, switch view to plain text mode 


    I am not sure what would be inside the definition of those above functions . As per suggestion i need to flatten down the existing tree hierarchy model and send it to the QCompleter.


    Some more hint or example is appreciated.


    Regards
    Sajjad

  7. #7
    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: QCompleter - isslplpue

    Take a piece of paper, draw a schema of your tree model (including branches and children) and think what needs to be done step by step to obtain a situation where the model is flat. When you find the algorithm of recalculating model indexes, implement it in mapFromSource() and mapToSource().
    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.


  8. #8
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QCompleter - isslplpue

    Hi

    If i flatten down the tree hierarchy , it will eventually look like a list model, right?


    Regards
    Sajjad

  9. #9
    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: QCompleter - isslplpue

    A list or a table model, depending on the number of columns your original model has.
    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.


Similar Threads

  1. Qcompleter
    By wambagilles in forum Qt Programming
    Replies: 7
    Last Post: 6th April 2011, 08:14
  2. QCompleter Help
    By shinegun in forum Qt Programming
    Replies: 0
    Last Post: 2nd September 2010, 13:26
  3. QCompleter & ToolTip
    By nanortemis in forum Qt Programming
    Replies: 3
    Last Post: 25th September 2009, 19:54
  4. QTextEdit and QCompleter
    By nivel in forum Qt Programming
    Replies: 2
    Last Post: 14th June 2009, 03:18
  5. Replies: 1
    Last Post: 12th October 2008, 08:21

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.