Results 1 to 9 of 9

Thread: Qpainter foreground

  1. #1
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Qpainter foreground

    hi,

    there are many widgets in a frame, Each widget contains rectangles in the extremities (QPainter::fillRect), rectangles are drawn in the frame. the problem is that rectange does not appear in the foreground.

    Thank you in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter foreground

    I don't really understand what you mean. Can you post a screenshot?
    How do you draw the rectangles in those widgets, how are the widgets within the frame layouted? Can you show some code.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter foreground

    hi,

    Thanks for your reponse,

    You finf bellow my code. "w" is the frame which contain widgets. i want that rectangle will be created in the foreground.
    if (m_infocus)
    {
    QWidget *w = this->parentWidget();
    if (w == obj && evt->type()==QEvent::Paint)
    {

    //Dessiner un conteneur de sélection
    QPainter painter(w);
    /*QPoint p = this->mapTo(w,QPoint(-4,-4));
    QPoint LT = w->mapFrom(w,p);
    QPoint LB = w->mapFrom(w,QPoint(p.x(),p.y()+this->height()));
    QPoint RB = w->mapFrom(w,QPoint(p.x()+this->width(),p.y()+this->height()));
    QPoint RT = w->mapFrom(w,QPoint(p.x()+this->width(),p.y()));*/

    /*painter.fillRect(LT.x(),LT.y(),8,8,QColor("#0101D F"));
    painter.fillRect(LB.x(),LB.y(),8,8,QColor("#0101DF "));
    painter.fillRect(RB.x(),RB.y(),8,8,QColor("#0101DF "));
    painter.fillRect(RT.x(),RT.y(),8,8,QColor("#0101DF "));*/


    return QWidget::eventFilter(obj,evt);
    }
    }
    return QWidget::eventFilter(obj, evt);

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter foreground

    The event filter gets the event before it reaches the target widget.
    When the widget finally recieved the paint event, it will just draw over whatever was in its buffer before.

    if you want to draw over the widget's content, you'll have to let it draw first.

    Cheers,
    _

  5. #5
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter foreground

    thanki you very much, your answer was very helpful for me.

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter foreground

    Custom painting is always done in QWidget::paintEvent.
    You can call the parent paintEvent and then do your drawing OVER it to get the foreground.

    From your code it seems you want to draw 4 small rect on the widgets corners if it has focus. Isn't it ?

  7. #7
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter foreground

    Yes that's right i want to draw 4 small rect on the widgets corners.

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter foreground

    Then simply override the QWidget::paintEventand check if the widget has focus (QWidget::hasFocus) and draw the rect on the corners.

  9. #9
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpainter foreground

    good it work now thank you

Similar Threads

  1. Different foreground colors in one Row (in QTreeView)
    By hunsrus in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2011, 14:46
  2. GraphicsView Foreground
    By augusbas in forum Qt Programming
    Replies: 11
    Last Post: 23rd June 2011, 12:06
  3. How to keep window in foreground
    By szicsi in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2008, 14:40
  4. Painting: How to control what's in the foreground?
    By Mister_Crac in forum Qt Programming
    Replies: 16
    Last Post: 8th May 2007, 13:00
  5. Updating Foreground for QGraphicsView
    By tts80 in forum Qt Programming
    Replies: 5
    Last Post: 4th January 2007, 15:28

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.