Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. French
  4. Problème méthode paint du délégué
Forum Update on Monday, May 27th 2025

Problème méthode paint du délégué

Scheduled Pinned Locked Moved Unsolved French
2 Posts 2 Posters 667 Views
  • 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.
  • L Offline
    L Offline
    lacombe
    wrote on 15 Jun 2019, 16:06 last edited by
    #1

    Bonjour,
    Dans la méthode paint d'un délégué, dans le code suivant, la valeur "value = index.model()......" reste toujours à 0 quand je clique dans la cellule.
    Voici le code, merci de votre aide.

    void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
          if (index.column() == 1)
        {
            painter->save();
            const int value = index.model()->data(index, Qt::DisplayRole).toInt();
            QRect rect(option.rect);
            const int width = (value * rect.width()) / 100;
            rect.setWidth(width);
            QColor c;
            if (value <= 20)
            {
              c = Qt::red;
            }
            else if (value <= 50)
            {
                c = QColor(240, 96, 0);
            }
            else
            {
                c = Qt::green;
            }
    
            painter->fillRect(rect, c);
            QTextOption o;
            o.setAlignment(Qt::AlignCenter);
            painter->drawText(option.rect, QString("%1 %").arg(value), o);
    
            painter->restore();
        }
        else
        {
            QStyledItemDelegate::paint(painter, option, index);
        }
    }
    
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on 17 Jun 2019, 20:50 last edited by
      #2

      Salut,

      Qu'elle est la valeur attendue et est-elle bien fixée dans le model avant l'appel du paint ?

      1 Reply Last reply
      0

      1/2

      15 Jun 2019, 16:06

      • Login

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