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. Delegate customization issue
Forum Updated to NodeBB v4.3 + New Features

Delegate customization issue

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 652 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.
  • Q Offline
    Q Offline
    qmad
    wrote on last edited by
    #1

    I am overriding the paint(...) function of QStyledItemDelegate as follows. I just want to display a red cross in all cells of a column on a QTableView. (I am applying this delegate for 3rd column only) What is wrong with the code? I am not able to see the cross mark in the cell. Instead I can see a red spot at top left corner of the table

    void CrossDelegate::paint(QPainter *painter,
    const QStyleOptionViewItem &option,
    const QModelIndex &index) const
    {
    painter->save();
    painter->setRenderHint(QPainter::Antialiasing, true);
    painter->setPen(QPen(Qt::red));
    painter->setBrush(option.palette.foreground());
    painter->drawLine(QPointF(0.0, 1.0) ,QPointF(1.0, 0.0) );
    painter->drawLine(QPointF(0.0, 0.0) ,QPointF(1.0, 1.0) );
    painter->restore();
    }

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @qmad said:

      Hi and welcome
      the painter is for whole widget. whole area.
      there should be a option.rect that should be the cell area.
      so the 0,0 would be rect.left, rect.top

      here is an example shown:
      http://www.informit.com/articles/article.aspx?p=1405547&seqNum=4

      Q 1 Reply Last reply
      0
      • mrjjM mrjj

        @qmad said:

        Hi and welcome
        the painter is for whole widget. whole area.
        there should be a option.rect that should be the cell area.
        so the 0,0 would be rect.left, rect.top

        here is an example shown:
        http://www.informit.com/articles/article.aspx?p=1405547&seqNum=4

        Q Offline
        Q Offline
        qmad
        wrote on last edited by
        #3

        @mrjj
        Thanks

        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