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
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
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,
_
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);
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,
_
thanki you very much, your answer was very helpful for me.
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 ?
Yes that's right i want to draw 4 small rect on the widgets corners.
Then simply override the QWidget::paintEventand check if the widget has focus (QWidget::hasFocus) and draw the rect on the corners.
good it work now thank you
Bookmarks