Results 1 to 2 of 2

Thread: Delegate customization issue

  1. #1
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Delegate customization issue

    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
    Qt Code:
    1. void CrossDelegate::paint(QPainter *painter,const QStyleOptionViewItem &option,const QModelIndex &index) const
    2. {
    3. painter->save();
    4. painter->setRenderHint(QPainter::Antialiasing, true);
    5. painter->setPen(QPen(Qt::red));
    6. painter->setBrush(option.palette.foreground());
    7. painter->drawLine(QPointF(0.0, 1.0) ,QPointF(1.0, 0.0) );
    8. painter->drawLine(QPointF(0.0, 0.0) ,QPointF(1.0, 1.0) );
    9. painter->restore();
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Delegate customization issue

    Use option.rect geometry instead of hard coded values.
    Option.rect is the geometry of your delegate.

    Ex: painter->drawLine(option.rect.topLeft() , option.rect.bottomRight());
    Last edited by prasad_N; 12th December 2015 at 10:48.
    Thanks :-)

Similar Threads

  1. QTabWidget customization
    By asafzakay in forum Qt Programming
    Replies: 16
    Last Post: 26th November 2017, 11:01
  2. Issue with custom delegate in tableview
    By alizadeh91 in forum Qt Programming
    Replies: 4
    Last Post: 13th April 2013, 08:39
  3. QMake QMake customization
    By csgib in forum Qt Tools
    Replies: 9
    Last Post: 15th June 2012, 08:59
  4. Customization of Qt Demo
    By nivditha in forum Newbie
    Replies: 7
    Last Post: 26th October 2010, 22:58
  5. QfileDialog customization
    By vjsharma_30 in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2010, 06:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.