Results 1 to 9 of 9

Thread: Highlighting the border of cell in Table

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Highlighting the border of cell in Table

    Create a new class which inherits QItemDelegate, and override:
    void QItemDelegate::drawFocus ( QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect ) const [virtual protected]
    Renders the region within the rectangle specified by rect, indicating that it has the focus, using the given painter and style option.
    At simplest possible, the implementation of drawFocus() could look something like this:
    Qt Code:
    1. void GridDelegate::drawFocus(QPainter* painter, const QStyleOptionViewItem &option, const QRect &rect) const
    2. {
    3. if (option.state & QStyle::State_HasFocus)
    4. {
    5. QPen pen(Qt::black);
    6. pen.setWidth(3);
    7. painter->setPen(pen);
    8. painter->drawRect(rect);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    Note: above code snippet is just a dummy example for you to get started. I suggest you to take a quick look at QItemDelegate sources, there you will get a neat reference from..

    Then, for example in the constructor of Grid, you would set the item delegate to the one you created:
    Qt Code:
    1. setItemDelegate(new GridDelegate(this));
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to jpn for this useful post:

    ankurjain (18th March 2006)

Similar Threads

  1. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 09:18
  2. Making Table cell as a combobox?
    By kaushal_gaurav in forum Qt Programming
    Replies: 9
    Last Post: 1st August 2008, 13:04
  3. Replies: 4
    Last Post: 4th February 2008, 07:16
  4. Highlighting a cell in QTable
    By sumsin in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 07:28
  5. Replies: 11
    Last Post: 8th September 2006, 00:15

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
  •  
Qt is a trademark of The Qt Company.