[Qt-interest] set backgrou color in cell (qtablewidget)

Sean Harmer sean.harmer at maps-technology.com
Mon Dec 7 21:19:58 CET 2009


Hi,

Moises Augusto wrote:
> Hi Arun,
> 
> thank's for help me.
> 
> the 'problem' is that the qsqltablemodel set all content on qtableview 
> and i don't know how to filter.
> 
> Moises

A coupleof options:

(i) Inherit your own class from QSqlTableModel and override the data() 
function to return a colur for the BackgroundRole based upon the data in 
that row.

Call the base class function for all other roles.

(ii) Use a proxy to do basically the same thing and place the proxy 
between your model and the view.

Sean

> 
> 2009/12/7 <ARUN_KUMAR at denso-diam.com <mailto:ARUN_KUMAR at denso-diam.com>>
> 
> 
>     I think you can use the following way
>     tableWidgetCell->setBackground(Qbrush(QColor(Qt::color)));
> 
>     Thanks & Regards,
>     Arun
> 
> 
> 
> 
>     *Moises Augusto <jr.jorro at gmail.com <mailto:jr.jorro at gmail.com>>*
>     Sent by: qt-interest-bounces at trolltech.com
>     <mailto:qt-interest-bounces at trolltech.com>
> 
>     12/07/2009 10:26 AM
> 
>     	
>     To
>     	qt-interest at trolltech.com <mailto:qt-interest at trolltech.com>
>     cc
>     	
>     Subject
>     	[Qt-interest] set backgrou color in cell (qtablewidget)
> 
> 
>     	
> 
> 
> 
> 
> 
>     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:
>     1
>     2
>     3
>     4
>     5
>     6
>     7 	model->setTable("table1");
> 
>     model->setFilter("id = " + grp.id <http://grp.id>);
>     model->setHeaderData(1,Qt::Horizontal, tr("ID"));
> 
>     model->setHeaderData(2,Qt::Horizontal, tr("NOME"));
> 
>     model->setHeaderData(3,Qt::Horizontal, tr("STATUS"));
> 
>     model->select();
>     tableview->setModel(model);
> 
> 
>     Guys, how to set background color in the cell 'STATUS' ?
> 
>     regards _______________________________________________
> 
>     Qt-interest mailing list
>     Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>     http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list