Results 1 to 6 of 6

Thread: Process the display data before displaying in QTreeView

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Process the display data before displaying in QTreeView

    HI
    i have set a model for the read only QTreeView .I want to show the data in the QTreeView after some processing of the models data has been done to display rather than showing it as the same in the model. The QAbstractItemDelegate class does not have any function to process the data before display .Any suggestions are appreciated.

  2. #2
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Process the display data before displaying in QTreeView

    Create your own custom model from QStandardItemModel, subclass data() to modify what is displayed and setData() to return whatever you want.

  3. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: Process the display data before displaying in QTreeView

    Different view has to display different data based on the same model.So returning data for a particular view from the data() function is not possible.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Process the display data before displaying in QTreeView

    Quote Originally Posted by babu198649 View Post
    Different view has to display different data based on the same model.So returning data for a particular view from the data() function is not possible.
    No problem. You have the "original" model called modelOriginal and two views A and B which displays the data of modelOriginal in different ways. So create two models modelForA and modelForB like this:
    Qt Code:
    1. class modelForA : public modelOriginal
    2. {...};
    3.  
    4. QVariant modelForA::data(...)
    5. {
    6. QVariant originalData = modelOriginal::data(...);
    7. // here alter the data for the model A and return it
    8. return modifiedData;
    9. }
    To copy to clipboard, switch view to plain text mode 


    VoilÃ

  5. The following user says thank you to Lykurg for this useful post:

    babu198649 (22nd June 2009)

  6. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: Process the display data before displaying in QTreeView

    Thank you,
    Really its a good idea, i all give it a try.

  7. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Process the display data before displaying in QTreeView

    And if you are using QTreeWidget, you could modify the data in delegates.
    You need to subclass QItemDelegateor QStyledItemDelegate and override the drawDisplay() or paint() function respectively.

Similar Threads

  1. QPixmap Display RGB data
    By phoenixtju in forum Qt Programming
    Replies: 2
    Last Post: 27th May 2009, 10:31
  2. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  3. Replies: 2
    Last Post: 29th September 2008, 00:08
  4. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14
  5. Display data from QStandardItemModel in QTreeView
    By jprice01801 in forum Qt Programming
    Replies: 7
    Last Post: 10th January 2007, 09:34

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.