PDA

View Full Version : Qpainter foreground



hassinoss
10th March 2014, 10:31
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

anda_skoa
10th March 2014, 12:19
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,
_

hassinoss
10th March 2014, 16:43
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("#0101DF"));
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);

anda_skoa
10th March 2014, 17:33
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,
_

hassinoss
11th March 2014, 09:58
thanki you very much, your answer was very helpful for me.

aamer4yu
11th March 2014, 14:04
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 ?

hassinoss
13th March 2014, 10:15
Yes that's right i want to draw 4 small rect on the widgets corners.

aamer4yu
13th March 2014, 11:08
Then simply override the QWidget::paintEvent
and check if the widget has focus (QWidget::hasFocus) and draw the rect on the corners.

hassinoss
13th March 2014, 11:32
good it work now thank you