Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Probleme with Grid Lines and QTreeView
Forum Updated to NodeBB v4.3 + New Features

Probleme with Grid Lines and QTreeView

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IbliSS
    wrote on last edited by
    #1

    Hi,

    I am using a QTreeView with a custom delegate and a subclassed QAbstractModel.
    I would like to see gridlines for items without children.

    At first display , everything's looks fine but whenever the mouse hovers over an item, the bottom or top line dissappears and reappears when hovering back to the item.

    First display is ok :
    !http://img4.hostingpics.net/pics/836040initialView.png(Initial View)!

    after hovering mouse over the last child ( commentaires )
    !http://img4.hostingpics.net/pics/339620hoveringView.png(hovering view)!

    I am using the following stylesheet for the QTreeItemView :

    @ QString treeViewStyle =
    "QTreeView { show-decoration-selected: 1; }"
    "QTreeView::item:hover { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 white);}"
    "QTreeView::item:selected:active { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 lightgray); color: black;}"
    "QTreeView::item:selected:!active { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 lightgray); color: black;}" ;
    ui->ProjetTreeView->setStyleSheet(treeViewStyle);@

    The paint method is reimplemented like this in my custom delegate :
    @if (index.column() > 0 && !index.model()->hasChildren(index))
    {
    QPen pen;
    pen.setColor(QColor(Qt::lightGray));
    pen.setWidth(1);
    painter->setPen(pen);
    painter->drawRect(option.rect);
    QStyledItemDelegate::paint(painter,option,index);
    }
    else QStyledItemDelegate::paint(painter,option,index);@

    Has anyone an idea of how to get rid of this dynamic behavior and keep the initial correct view at first display ?

    Hope this description is quiet clear, if not feel free to ask me more details, this is my first post here ;)

    Thanks a lot,

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      welcome to forum. Can you try removing the following line in stylesheet and see how it works.

      QTreeView::item:hover { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 white);}"

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • I Offline
        I Offline
        IbliSS
        wrote on last edited by
        #3

        Thanks for this answer.

        I have removed the line and even without using stylesheet at all, the problem is still here.

        I understand that, each time an item is hovered, the view is calling the paint method from the delegate and passing all its indexes of the item. Say my item is at row 2 and i have 3 columns, then the corresponding index.row() and index.column() in the paint method will show (2,0) ; (2;1) ; (2;2).

        Just to complete my previous post, i don't subclass QTreeView.

        1 Reply Last reply
        0
        • I Offline
          I Offline
          IbliSS
          wrote on last edited by
          #4

          I finally found a way to get a similar display without this mouse hovering issue, using stylsheet.

          My paint method is simply calling the base class paint method from QStyledItemDelegate

          @void ProjetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
          {
          QStyledItemDelegate::paint(painter,option,index);
          }@

          and the stylesheet is defined as :

          @QString treeViewStyle =
          "QTreeView { show-decoration-selected: 1; }"
          "QTreeView::item:has-children:open {background-color: lightgray;}"
          "QTreeView::item:!has-children { border: 0.5px ; border-style: solid ; border-color: lightgray ;}"
          "QTreeView::item:hover { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 white); }"
          "QTreeView::item:selected:active { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 lightgray); color: black; }"
          "QTreeView::item:selected:!active { background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 lightgray, stop: 1 lightgray); color: black;}" ;
          ui->ProjetTreeView->setStyleSheet(treeViewStyle);@

          leading to the following result :
          !http://img4.hostingpics.net/pics/586918Alternativesolution.png(alternative solution)!

          However, it's not exactly what i wanted intially and i hope there is a better solution.

          Thanks for your help.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved