[Qt-interest] Highlighted QTreeWidgetItem inside a QTreeWidget.

phil prentice philp.cheer at talktalk.net
Wed Nov 3 17:18:34 CET 2010


Thanks
  I dont know if this was the best way, but I did the following:-

// Set the highlighted text colour to show the state of this network.
  NetListDataItem *item =
                (NetListDataItem *)current->data(0, Qt::UserRole).toInt();
  // Set colour to show if network unstable.
  QColor color(((item) && (item->networkStatus() ==
                                NetListDataItem::e_unstable))?"red":"white");
  QPalette highlight;
  highlight.setColor(QPalette::HighlightedText,color);
  m_netRouting->setPalette(highlight);  //QTreeWidget 

So I set the palette highlight color of the QTreeWidget item appropriately 
every time a row is selected (currentItemChanged() signal)
It seems to work ok; the only disadvantage was that all of the columns of the 
selected rows text gets turned to red, not just column 1.

But I am happy

Thanks again
Phil


On Wednesday 03 November 2010 12:08, Eckhard Jokisch wrote:
> On Wednesday 03 November 2010 13:06:03 phil prentice wrote:
> > Hi
> >   I have a list of QTreeWidgetItem's inside of a QTreeWidget.  In certain
> > circumstances I modify the text (for column 1) to be displayed in red
> > i.e.
> >
> > tableItem->setForeground(1, QBrush(QColor("red")));
> >
> > This works great.  Unfortunately when I highlight that entry in the table
> > the text is automatically converted to white with a blue background for
> > all the columns. So I dont actually know that item is displyed in red.
> >
> >   Is there any nice way of making the highlighted entry still have red
> > text for that column(if it applies)..or is there something else you might
> > recommend.
> >
> > Thanks
> > Phil
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> Not knowing if this will work I would suggest looking at the EditRole and
> changing the colors there. Another option would be to install a different
> delegate on that item.
>
> Eckhard
> _______________________________________________
> 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