QTreeWidget expand/collapse indicator issue



  • Environment:
    Windows 7 x 64, Visual Studio 2010, Qt 4.8.2

    Problem:
    The expand/collapse indicator on the QTeeWidget colors itself after painting a QTreeWidgetItem.
    This is something that is very difficult to explain and is better understood with an example.
    I have created a visul studio 2010 solution that demonstrates the problem and can be found here.
    "QTreeWidgetIssue.zip":http://www.codedconsulting.com/temp
    Its too much code to post here.

    Procedure

    1. Open the VS .sln file.
    2. Build and execute the program.
    3. On the GUI navigate the tree to see what is there. Its a demo app, so not much just a tree with 5 top level items with 3 sub items per top item.
    4. Press the Do Border button. You will see that WordGroup1 and VarGroup1 are "bordered green". This is exactly what I want.
      It signifies that something has changes for thess groupings.
      But also notice that the expand/collapse indicators for the WordGroups below the "bordered" WordGroup1 are colored,
      unlike the normal expand/collapse indicators above the "bordered" WordGroup1.
    5. Close the application, It crashes but who cares this is just a demo app.
    6. Open the main.cpp file comment out lines 11 and 12.
      QCleanlooksStyle* pStyle = new QCleanlooksStyle();
      QApplication::setStyle( GetSubclassStyleForBaseStyle( pStyle ) );
    7. Build and execute the program.
    8. Press the Do Border button. This time the expand/collapse indicators are not colored.

    Unfortunately I require the QCleanlookStyle for other things, so I cannot just get rid of it.
    I would like to know if there is a way to modify the application, maybe in the CStyledTreeItemDelegate::paint() to solve or work around this issue.
    Any ideas are greatly appreciated.

    Thank you,
    Brian Holland



  • I was actually able to solve this with some simple CSS. I added the following CSS to the QTreeWidget in the .ui file, after adding a couple images to the project and adding those images to the .qrc.
    @QTreeView::branch:has-children:!has-siblings:closed, QTreeView::branch:closed:has-children:has-siblings
    {
    image: url(:/Images/tree-expand);
    }
    QTreeView::branch:open:has-children:!has-siblings, QTreeView::branch:open:has-children:has-siblings
    {
    image: url(:/Images/tree-collapse);
    }@


Log in to reply
 

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