Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStyledItemDelegate + QTreeView::setIndenation causes glitches on text drawing
Qt 6.12 LTS is out! See what's new in the release blog

QStyledItemDelegate + QTreeView::setIndenation causes glitches on text drawing

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.0k 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.
  • MikhailGM Offline
    MikhailGM Offline
    MikhailG
    wrote on last edited by
    #1

    It has been two days I can not get the solution.

    I have a custom QStyledItemDelegate and a QTreeView. QTreeView's indentation set to 12. And QStyledItemDelegate's QStyleOptionViewItem::rect set to -12. This set up causes glitches when I change the color of the QTreeView item's text.

    0_1552579096612_ыы.gif

    void MyItemViewDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const
    {
        if (m_functor->operator ()(index))
        {
            option->rect.adjust(-12, 0, 0, 0);
        }    
    }
    
    MyTreeView::MyTreeView(QWidget* parent)
        : QTreeView(parent)
    {
        setIndentation(12);
    }
    

    What did I miss?

    1 Reply Last reply
    0
    • MikhailGM Offline
      MikhailGM Offline
      MikhailG
      wrote on last edited by
      #2

      So What I forgot to do was to override:

      QRect QTreeView::visualRect(const QModelIndex& index) const
         {
             if (m_functor->operator ()(index))
             {
                 return QTreeView::visualRect(index).adjusted(-m_indentation, 0, 0, 0);
             }
      
            return QTreeView::visualRect(index);
         }
      
      1 Reply Last reply
      1

      • Login

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