Results 1 to 20 of 47

Thread: A few queries about Model View Programming

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A few queries about Model View Programming

    1) I am using setIndexWidget() to display checkboxes in the 4th column and my code is working fine. Is it ok or should i use QItemDelegate to add checboxes?
    According to my experience with the model/view,If you use delegate, you would change the model either.

    2) Currently the QTableView displays data directly received from the model (database). But suppose, i want to format the data received from the model before displaying on the QTableView, how can i do it? For e.g. suppose the "time" field is stored as seconds in the database and i want to display it in "minutes:seconds" in the QTableView, how can i do that?
    you can write the data() function in the model like this
    Qt Code:
    1. if (role == Qt::DisplayRole)
    2. {
    3. if(index.column() == column_time)
    4. {
    5. //seconds is the "time" field stored value
    6. int min = seconds/60;
    7. int sec = seconds%60;
    8. return QString(%1:%2).arg(min).arg(sec);
    9. }
    10. //.......
    11. }
    To copy to clipboard, switch view to plain text mode 

    3) I want to do custom drawing in the "tracks" field, for e.g. the currently playing track might have an icon next to the track name. How to do that?
    also in the data() func
    Make a QIcon,return it when role == Qt:: DecorationRole
    Last edited by calmspeaker; 12th December 2008 at 03:34.
    Jerry

  2. The following user says thank you to calmspeaker for this useful post:

    montylee (15th December 2008)

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  2. model View programming problem
    By mismael85 in forum Qt Programming
    Replies: 3
    Last Post: 2nd April 2008, 21:44
  3. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  4. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 13:01
  5. Replies: 6
    Last Post: 20th April 2006, 10:23

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