Results 1 to 4 of 4

Thread: QTreeView show-decoration-selected has no effect

  1. #1
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTreeView show-decoration-selected has no effect

    I'm trying to change the selection behaviour in a QTreeView using a stylesheet. The show-decoration-selected property seems to have no effect.

    I'm calling the following in my QMainWindow:

    Qt Code:
    1. setStyleSheet(
    2. "QTreeView {"
    3. " selection-background-color: navy;"
    4. " alternate-color: white;"
    5. " alternate-background-color: rgb(240,240,240);"
    6. " show-decoration-selected: 1;"
    7. "}"
    8. );
    To copy to clipboard, switch view to plain text mode 

    The alternate-background-color property does have an effect, so I know that the QTreeView is using the stylesheet. But switching show-decoration-selected from 0 to 1 has no effect at all. How should the show-decoration-selected property affect a QTreeView?

    I would like to have the entire row selected from the extreme left of the QTreeView to the extreme right of the QTreeView regardless of the level/depth of the item in the QTreeView. And I would like the selection-background-color to be navy and selection-color to be white.

    I have had this styling working for a QTableView. Any reason why it shouldn't be possible for a QTreeView?

    I'm on Windows 7 using C++ Qt 4.6.2 in Visual Studio 2008.

  2. #2
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView show-decoration-selected has no effect

    This is how I create and initialise the QTreeView in my CTreeViewWidget.

    Qt Code:
    1. treeView.reset(new QTreeView(this));
    2. treeView->setModel(&model);
    3. treeView->setFocusPolicy(Qt::NoFocus);
    4. treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    5. treeView->setAlternatingRowColors(true);
    6. treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
    7. treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
    8. treeView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
    9. treeView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
    10. treeView->setSortingEnabled(false);
    11. treeView->header()->setStretchLastSection(false);
    12. treeView->header()->setDefaultAlignment(Qt::AlignCenter);
    13. treeView->header()->setDefaultAlignment(Qt::AlignHCenter);
    14. treeView->header()->setHighlightSections(false);
    15. treeView->header()->setMovable(true);
    To copy to clipboard, switch view to plain text mode 

    I've also noticed that the last section of the header stretches to the end even though I call setStretchLastSection(false). I would prefer this not to happen. Any ideas on how to prevent the last section from stretching?

  3. #3
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView show-decoration-selected has no effect

    bump, bump, bump, bump.

  4. #4
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView show-decoration-selected has no effect

    Right, it seems that "show-decoration-selected" does have an effect, just not the effect that I was expecting. On Windows 7 it "glows" the expand/collapse icon to the left of a node with children.

    However the description of the property does not explain this behaviour at all:

    Controls whether selections in a QListView cover the entire row or just the extent of the text.

    If this property is not specified, it defaults to the value specified by the current style for the SH_ItemView_ShowDecorationSelected style hint.

    Example:

    * { show-decoration-selected: 1 }
    I have managed to achieve something closer to what I'm after by using a stylesheet, particularly:

    Qt Code:
    1. show-decoration-selected: 1;
    2. selection-color: white;
    3. alternate-background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #EFEFEF, stop: 1 #DFDFDF);
    4. }
    5.  
    6. QTreeView::item {
    7. border: transparent;
    8. }
    9.  
    10. QTreeView::item:!selected:hover {
    11. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D0D0D0, stop: 1 #CFCFCF);
    12. }
    13.  
    14. QTreeView::item:selected:!hover{
    15. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #8F9CBF, stop: 1 #838FAF);
    16. }
    17.  
    18. QTreeView::item:selected:hover{
    19. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #7888AF, stop: 1 #6D7C9F);
    20. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Show selected rows
    By mpi in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2010, 01:59
  2. Replies: 1
    Last Post: 10th June 2010, 05:35
  3. QTreeView: make root decoration appear on visual column 0
    By chezifresh in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2008, 02:36
  4. qtopia window decoration cannot show caption
    By qtopiahooo in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 13th March 2007, 08:09
  5. window decoration cannot show caption
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 31st January 2007, 08:17

Tags for this Thread

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.