Results 1 to 6 of 6

Thread: Bind entire class /structure to a view control

  1. #1
    Join Date
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question Bind entire class /structure to a view control

    Hi,

    I have a structure consists of 5 fields each of different data type which I want to bind to a Treeview control. Even though entire structure is mapped, the Treeview should list only one field from the structure. How to do ModelView in this scenario and how can I filter out which one to display. I am expecting a approach similar to WPF (model) ,where we can bind entire class object to the view. Please help as i have no idea of how to proceed

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Bind entire class /structure to a view control

    The usual solution in this case is to put a QSortFilterProxyModel between your source model and the QTreeView (in Qt land, there are "views" and "widgets", not "controls" - you need to clear your brain of the WPF and MFC poisons ). You will derive a new class from QSortFilterProxyModel and reimplement the QSortFilterProxyModel::filterAcceptsRow() or filterAcceptsColumn() methods (along with the map*(), data(), rowCount(), columnCount() and probably some other methods. The filterAccepts*() functions are Boolean methods, which return true if the row / column should be displayed and false otherwise.

    There is too much detail to go into here. You should take a look at the QSortFilterProxyModel documentation and at the Qt examples for basic and custom filters.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Bind entire class /structure to a view control

    Thank you so much!

  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: Bind entire class /structure to a view control

    For simple cases maybe it's enough to hide unwanted columns directly in the view.
    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
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Bind entire class /structure to a view control

    How can I show only one column if i have 6 columns?

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Bind entire class /structure to a view control

    How can I show only one column if i have 6 columns?
    Maybe by calling QTreeView::setColumnHidden() ?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 24th February 2016, 17:00
  2. Stroing class objects in a structure
    By subrat17june in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2013, 07:47
  3. Replies: 4
    Last Post: 5th September 2010, 10:08
  4. Qt::ItemIsSelectable in a model/view structure
    By schall_l in forum Qt Programming
    Replies: 5
    Last Post: 12th February 2008, 11:42
  5. Replies: 1
    Last Post: 1st March 2006, 11:43

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.