Results 1 to 3 of 3

Thread: How to change text displayed in multiple cells in QTableView?

  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default How to change text displayed in multiple cells in QTableView?

    I have a QTableView set with QSqlQueryModel, it has multiple columns from which the last 2 columns have values 0 and 1(both columns have cells with 0 and 1, and not 1 column with 0 and what column with 1).
    I would like to replace 0=No and 1=Yes, how can I achieve this?
    My main issue is with finding those cells as I found most examples using delegates but those examples are about editing the cells you want and know.

    Any help is appreciated.

  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: How to change text displayed in multiple cells in QTableView?

    There are many possible ways to do that.

    One is to derive from QSqlQueryModel and reimplement the data() method.
    When DisplayRole values of those two columns are requested, you get the numerical value from the base class and the return the respective string.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    adutzu89 (14th February 2014)

  4. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to change text displayed in multiple cells in QTableView?

    Thank you for your answer, atm I managed to solve it easier by using replace function inside MySql query, I will try experimenting with delegates until I can understand them properly, because in the near future I would want to add some buttons inside the view.
    Last edited by adutzu89; 14th February 2014 at 09:43.

Similar Threads

  1. Change QTableView's index number displayed
    By rex in forum Qt Programming
    Replies: 0
    Last Post: 6th April 2011, 15:30
  2. How do i change background of QTableView cells
    By .:saeed:. in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2011, 14:42
  3. Lists/multiline text in QTableView cells
    By dv_ in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2008, 23:43
  4. how to change text color in QTableView?
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2008, 10:03
  5. Text in QTableView cells not visible
    By juliarg in forum Newbie
    Replies: 2
    Last Post: 22nd March 2007, 15:49

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.