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. List view not Displaying all The Time
Forum Updated to NodeBB v4.3 + New Features

List view not Displaying all The Time

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.6k 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.
  • M Offline
    M Offline
    maxy
    wrote on last edited by
    #1

    Hi ,

           I have a problem with displaying List view. We are having an customized item delegate for this list where we overwrite the paint event.The Problem is the list does not display on UI When it is loaded.The list is displayed when we generate an mouse Press event in list.Please Give your Ideas and suggestion to solve this.
    

    I am adding customized delegate code for your better understanding.

    @void CItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
    {
    painter->save();

    if( option.state & QStyle::State_Sunken )
    {
        painter->fillRect( option.rect, option.palette.highlight() );
    }
    if( m_connectionStatus && ( m_selectedIndex == index.row() ) )
    {
        QPixmap selectionIndicator = icons[10];
        painter->drawPixmap( option.rect.width() - selectionIndicator.width() - 10, option.rect.top() + option.rect.height() / 2 - selectionIndicator.height() / 2, selectionIndicator );
    }
    
    // Draw the icon
    QVariantList fields = index.data().toList();
    QPixmap  icon = icons[fields[IconIndex].toInt()];
    
    painter->drawPixmap( 14, option.rect.top() + option.rect.height() / 2 - icon.height() / 2, icon );
    
    QFont f( painter->font() );
    f.setPixelSize( 23 ) ;
    f.setBold( true );
    painter->setFont( f );
    
    // Draw the error description text, truncated if necessary
    static const int TextLeftMargin = 80;
    static const int TextTopBottomMargin = 25;
    
    QString elidedDescription = painter->fontMetrics().elidedText( fields[Description].toString(), Qt::ElideRight, 352 );
    painter->drawText( option.rect.adjusted( TextLeftMargin, TextTopBottomMargin, 0, 0 ),  Qt::AlignLeft, elidedDescription );
    
    // Divider
    QRect dividerRect = option.rect;
    dividerRect.setTop( dividerRect.bottom() );
    QLinearGradient gradient( 0, 0, option.rect.width() / 2, 0 );
    gradient.setColorAt( 0, QColor( 144, 144, 144, 0 ) );
    gradient.setColorAt( 1, QColor( 144, 144, 144, 255 ) );
    gradient.setSpread( QGradient::ReflectSpread );
    painter->fillRect( dividerRect, gradient );
    
    painter->restore();
    

    }@

    Thanks In Advance.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Did you check whether the delegate's paint() is called when application loads ?
      Did you reimplement sizeHint() ?

      157

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NicuPopescu
        wrote on last edited by
        #3

        Hi,

        afaik if the item delegate is set before entering the app's event loop (first showing) then the overridden paint is called ...

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxy
          wrote on last edited by
          #4

          Yes.I implemented the SizeHint() function

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxy
            wrote on last edited by
            #5

            I observe that my listview paintevent is called on first time load,but the listview does not display anything, my code is below:

            void CListView::paintEvent( QPaintEvent* e )
            {

            QListView::paintEvent( e );//I get QPainter::begin: Widget painting can only begin as a result of a paintEvent

            if( pressedIndex.isValid() )//I want to custom paint only when a row is pressed
            {
            
                qDebug( "CListView::paintEvent() - pressed Index valid" );
            
                QPainter painter( viewport() );
            
                QStyleOptionViewItem option = viewOptions();
            
                option.rect = visualRect( pressedIndex );
            
                if( !draggedAway )
                {
            
                    option.state |= QStyle::State_Sunken;
            
                }
            
                if( pressedIndex == currentIndex() )
            
                {
            
                    option.state |= QStyle::State_Selected;
            
                }
            
                itemDelegate()->paint( &painter, option, pressedIndex );
            
            }
            
            else
            
            {
            
                qDebug( "CListView::paintEvent() - pressed Index Invalid" );
            
            }
            

            }

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              You should rather handle that directly in the paint function of your delegate.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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