QTreeWidget indicator area background color



  • How do I set the background color of the indicator area of a QTreeWidget?
    If I put the the following code in the constructor of a default Qt GUI app

    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    tw = new QTreeWidget(this);
    tw->viewport()->setBackgroundRole(QPalette::Background);
    tw->setAutoFillBackground(true);
    tw->setAttribute(Qt::WA_MacShowFocusRect, false);
    tw->setColumnCount(1);
    tw->setHeaderHidden(true);
    tw->setIndentation(10);
    setCentralWidget(tw);
    
    QTreeWidgetItem *i;
    
    i = new QTreeWidgetItem(tw);
    i->setBackground(0,   this->palette().brush(QPalette::Background));
    i->setText(0,  "test 1");
    
    i = new QTreeWidgetItem(tw);
    i->setBackground(0,   this->palette().brush(QPalette::Background));
    i->setText(0,  "test 2");
    
    QTreeWidgetItem *i2;
    
    i2 = new QTreeWidgetItem(i);
    i2->setBackground(0,   this->palette().brush(QPalette::Background));
    i2->setText(0,  "child 1");
    
    i2 = new QTreeWidgetItem(i);
    i2->setBackground(0,   this->palette().brush(QPalette::Background));
    i2->setText(0,  "child 2");
    

    }
    @
    under OSX, the QTreeWidget is displayed ok.
    But under Linux (Fedora), there is a white strip to the left of the text.



  • I'm wondering if it's a deprecation issue...

    From "QWidget's Class Reference page:":http://doc.trolltech.com/4.7-snapshot/qwidget.html#autoFillBackground-prop

    autoFillBackground : bool

    This property holds whether the widget background is filled automatically.

    If enabled, this property will cause Qt to fill the background of the widget before invoking the paint event. The color used is defined by the QPalette::Window color role from the widget's palette.

    In addition, Windows are always filled with QPalette::Window, unless the WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.

    From "QPalette's Class Reference page:":http://developer.qt.nokia.com/forums/viewthread/5279/

    QPalette::Window 10 A general background color.
    QPalette::Background Window This value is obsolete. Use Window instead.

    Have you tried setting QPalette::Window instead of QPalette::Background? I'm guessing that is where the problem lays. Once you do that, you shouldn't need to SetBackground on each QTreeWidgetItem, unless of course you're planning on using different colors on each one...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.