Results 1 to 2 of 2

Thread: QListView with QSqLite and special format

  1. #1
    Join Date
    Sep 2015
    Posts
    23
    Thanks
    1

    Default QListView with QSqLite and special format

    I have a QListView which I fill with a QSqlQueryModel that select datasets from the QSqLite database.
    The datasets I get have two columns:
    Qt Code:
    1. | msg | ownership |
    2. ----------------------
    3. | test1 | 0 |
    4. | test2 | 1 |
    5. | test3 | 1 |
    6. | test4 | 0 |
    7. ----------------------
    To copy to clipboard, switch view to plain text mode 

    The ownership specifies if the messages was sent (0) or received (1).
    When I fill the QListView with the data I don't wanna display the ownership, but according to it set the text color and perform an alignment.
    e.g. it should look something like this

    Qt Code:
    1. text1 <-- color red
    2. text2 <-- color green
    3. text3 <-- color green
    4. text4 <-- color red
    To copy to clipboard, switch view to plain text mode 


    Does anyone know how to do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView with QSqLite and special format

    Three options

    1) use an item delegate that uses the ownership value and decides how to draw on that
    2) derive from QSqlQueryModel and reimplement data() to answer for the alignment role and background role depending on the value of ownership
    3) do the same thing with a class derived from QIdentityProxyModel with the QSqlQueryModel as the source.

    Cheers,
    _

Similar Threads

  1. Qt to Matlab (mat format) export data to Matlab .mat format -v4
    By windsword in forum Qt-based Software
    Replies: 4
    Last Post: 26th February 2013, 20:01
  2. Replies: 2
    Last Post: 3rd June 2011, 07:39
  3. Replies: 5
    Last Post: 1st June 2011, 08:28
  4. Replies: 1
    Last Post: 14th January 2011, 11:57
  5. Replies: 0
    Last Post: 21st July 2010, 10:32

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.