Results 1 to 2 of 2

Thread: set backgrou color in cell (qtablewidget) if cell in database is true

  1. #1
    Join Date
    Dec 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default set backgrou color in cell (qtablewidget) if cell in database is true

    Hi!

    please, help me in the problem.

    In the cell (database) is true or false.. when true, the background collor should be green, when false, shoulde be red (in qtablewidget).

    I'm using qsqltablemodel for set table in qtablewidget:

    Qt Code:
    1. model->setTable("table1");
    2. model->setFilter("id = " + grp.id);
    3. model->setHeaderData(1,Qt::Horizontal, tr("ID"));
    4. model->setHeaderData(2,Qt::Horizontal, tr("NOME"));
    5. model->setHeaderData(3,Qt::Horizontal, tr("STATUS"));
    6. model->select();
    7. tableview->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    Guys, how to set background color in the cell 'STATUS' ?

    regards

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: set backgrou color in cell (qtablewidget) if cell in database is true

    you can use QAbstractItemModel::setData + Qt::BackgroundRole or write your own delegate.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.