Results 1 to 4 of 4

Thread: QTreeWidgetItem background

  1. #1
    Join Date
    Sep 2008
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QTreeWidgetItem background

    QTreeWidgetItem *familyItem = new QTreeWidgetItem(fontTree);


    familyItem->setText(0, family);
    familyItem->setCheckState(0, Qt::Unchecked);
    familyItem->setBackground(0,QColor(202, 0, 0, 255));

    I want to color each item,but setbackground is changing only the color of first item.Any guess,why its not painting the item?.Looking for help

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidgetItem background

    setBackground takes column as the first argument.
    If you want to set color for the whole row, u will need to call setBackground on all columns

  3. #3
    Join Date
    Sep 2008
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTreeWidgetItem background

    Thanks for your reply.
    I have only one column but n number of rows.My first row is getting the color.I want to color all the rows
    Thanks

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidgetItem background

    I guess you will need to iterate all items and set the color.

    Other mehtod is to use delegates. I tried using it, but was not able to set the background color.
    QTreeWidget uses delegates to render the items. I used QItemDelegate, but its drawBackground function was not being called. Only paint() was called. Also tried QStyledItemDelegate, but it doesnt have drawBackground function. Seems have to use paint() only..

    I will let u know if i succeed. its late now... gotta sleep

Similar Threads

  1. QTreeWidgetItem and background color
    By swiety in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2016, 07:25
  2. Replies: 5
    Last Post: 21st July 2010, 22:51
  3. QTreeWidgetItem: reset background color
    By supergillis in forum Qt Programming
    Replies: 4
    Last Post: 3rd August 2008, 13:12
  4. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  5. Replies: 1
    Last Post: 5th April 2006, 16:44

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.