title: HowTo draw ico+text data with delegate in QTreeWidget (when selecting a row)?
body: <p><strong>Problem</strong>: When I select a row with a mouse on the table, <em>pic #1</em> becomes <em>pic #2</em> - as you can see, all my drawn icons are disappear! </p>
  
  <p><strong>Question</strong>: could anyone help me with this problem? Maybe some one already fall in with this dilemma and solve it? Thnks!</p>
  
  <p><strong>pic #1</strong></p>
  
  <p><img src="https://i.stack.imgur.com/FX2jp.png" alt="enter image description here"></p>
  
  <p><strong>pic #2</strong></p>
  
  <p><img src="https://i.stack.imgur.com/8KyZw.png" alt="enter image description here"></p>
  
  <p><strong>Additional</strong>: I'm using <code>QTreeWidget</code> as a table with some data (<em>hidden root</em>). To <code>QTreeWidget</code> object I append column delegates (for 1, 2 and 3 columns, but not for the 4! column). In all delegates (which are based on <code>QStyledItemDelegate</code> class) I have re implement <code>paint()</code> method, to draw my specific icons or text data.</p>
  
  <p>Here is the code of one of the delegates (1 column) - it's some kind of chain, some items grouped together (parent + childs):</p>
  
  <pre><code>void ChainTableDelegate::paint( QPainter* painter, const QStyleOptionViewItem&amp; option, const QModelIndex&amp; index ) const
  {
       QStyleOptionViewItem op = option;
       op.state &amp;= ~QStyle::State_HasFocus;
  
       if( index.column() == TreeView::ePosChain )
       {
            QModelIndex parentIndex = index.parent();
  
            if( !childCount( index ) &amp;&amp; !parentIndex.isValid() )
            {
                 QStyledItemDelegate::paint( painter, op, index );
                 return;
            }
  
            if( !parentIndex.isValid() )
            {
                 // top
                 painter-&gt;drawPixmap( pos( op, topActivePix_ ), topActivePix_ );
            }
            else
            {
                 int row = index.row();
                 if( row != childCount( parentIndex ) - 1 )
                 {
                      // middle
                      painter-&gt;drawPixmap( pos( op, middleActivePix_ ), middleActivePix_ );
                 }
                 else
                 {
                      // bottom
                      painter-&gt;drawPixmap( pos( op, bottomActivePix_ ), bottomActivePix_ );
                 }
            }
       }
  
       QStyledItemDelegate::paint( painter, op, index );
  }
  </code></pre>