Results 1 to 2 of 2

Thread: Two-colored cell in item view

  1. #1
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post Two-colored cell in item view

    Hi,
    I want to make two-colored cell in QTableView.
    I made my delegate class with the following paint method:

    Qt Code:
    1. void BitViewDelegate::paint(QPainter *painter,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index) const
    4. {
    5. QString text = index.model()->data(index, Qt::DisplayRole).toString();
    6. QString l = text.left(5);
    7. QRect myRect = option.rect;
    8. myRect.setX(option.rect.x() + option.fontMetrics.width(l));
    9. myRect.setWidth(option.rect.width() - option.fontMetrics.width(l));
    10. painter->fillRect(myRect, Qt::green);
    11. QItemDelegate::paint(painter, option, index);
    12. }
    To copy to clipboard, switch view to plain text mode 

    But there is a little problem. My rectangle and previous character (the one before the text.left(5) string) overlap.
    It seems to me that there is a little margin between the border of the cell and default delegate.
    How it can be calculated?
    Or is there any other better solution how to make two-colored cells?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Two-colored cell in item view

    For calculating such things see QStyle::styleHint().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. list view displaying same item value...
    By addu in forum Newbie
    Replies: 1
    Last Post: 30th May 2009, 01:55
  2. list view item problem..
    By addu in forum Qt Programming
    Replies: 5
    Last Post: 29th May 2009, 11:26
  3. Default Item View classes and returning data from model
    By xerionn in forum Qt Programming
    Replies: 8
    Last Post: 23rd April 2009, 19:50
  4. multi-select editing in an item view
    By chezifresh in forum Qt Programming
    Replies: 0
    Last Post: 4th February 2009, 02:14
  5. View, Scene, Item and thread??
    By dungsivn in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 19:21

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.