Results 1 to 4 of 4

Thread: Problem in Paint Focus for Q3Table

  1. #1
    Join Date
    Feb 2013
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Problem in Paint Focus for Q3Table

    I had a class MyTable inherited from Q3Table.
    I want to highlight the cell that's clicked by mouse by adding a red rectangular around the cell's bundary.
    So I re-implemented paintFocus(QPainter * p, const QRect & cr) like this:

    void MyTable:aintFocus ( QPainter * painter, const QRect & cr )
    {
    Q3Table:aintFocus(painter,cr);
    painter->setPen(QPen(QColor(155,10,10), 2));
    QRect highlight_rect = cr.adjusted(2,2, -2, -2);
    painter->drawRect(highlight_rect);
    update();
    }

    But the red Rect only appear for the first column in the first row. When clicking other cells, just the default black frame.
    Why????????
    Capture1.PNG Capture2.PNG

  2. #2
    Join Date
    Feb 2013
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in Paint Focus for Q3Table

    simply put, given the col and row number, how to hight light the cell?

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    12
    Thanked 142 Times in 135 Posts

    Default Re: Problem in Paint Focus for Q3Table

    From the Q3Table::paintFocus() docs:
    The painter p is already translated to the cell's origin, ...

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Problem in Paint Focus for Q3Table

    Try removing the call to QWidget::update() because all this Qt 3 compatibility code is likely called from within QWidget::paintEvent() of the Qt4 widget wrapper and, as the docs say:
    Note: Generally, you should refrain from calling update() or repaint() inside a paintEvent(). For example, calling update() or repaint() on children inside a paintevent() results in undefined behavior; the child may or may not get a paint event.

    If you are writing a new program do not continue use the Qt 3 compatibility classes. Learn to use the Qt4/5 QTableWidget or QTableView.

Similar Threads

  1. Q3Table vs QTableWidget
    By batileon in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2008, 10:38
  2. Q3Table text alignment problem
    By batileon in forum Qt Programming
    Replies: 4
    Last Post: 28th August 2008, 19:04
  3. Problem about porting Q3Table to QTableWidget
    By batileon in forum Qt Programming
    Replies: 0
    Last Post: 28th August 2008, 12:18
  4. Q3Table event filter problem
    By batileon in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2008, 11:40
  5. Q3Table performance problem
    By batileon in forum Qt Programming
    Replies: 1
    Last Post: 13th August 2008, 16:32

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.