Qt-interest Archive, April 2008
Problem with QGraphicsTextItem
Message 1 in thread
Hi,
i got a little problem regarding QGraphicsTextItem: i just want such an
item with a border drawn and a definite margin between border and text.
So i did:
void GETextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *widget = 0)
{
painter->drawRoundedRect(0, 0, boundingRect().width(),
boundingRect().height(), 5, 5);
QGraphicsTextItem::paint(painter, option, widget);
}
QRectF GETextItem::boundingRect()
{
const QRectF t = QGraphicsTextItem::boundingRect();
QRectF t2;
t2.setHeight(t.height()+20);
t2.setWidth(t.width()+20);
return t2;
}
QPainterPath GETextItem::shape() const
{
const QRectF t = QGraphicsTextItem::boundingRect();
QRectF t2;
t2.setHeight(t.height()+20);
t2.setWidth(t.width()+20);
QPainterPath path;
path.addEllipse(t2);
return path;
}
This draws the border (with margin) but if i move the item the 'bottom'
- the area outside the usual QGraphicsTextItem - is not redrawn (so
there are points left).
What am i doing wrong?
Thx for any help,
RZ
--
[ signature omitted ]
Message 2 in thread
Your bounding rectangle is smaller than the shape.
The bounding rectt is used to find what has to be redrawn.
-----Ursprüngliche Nachricht-----
Von: RZ [mailto:rz@xxxxxxxxxxxx]
Gesendet: Montag, 14. April 2008 15:38
An: qt-interest@xxxxxxxxxxxxx
Betreff: Problem with QGraphicsTextItem
Hi,
i got a little problem regarding QGraphicsTextItem: i just want such an
item with a border drawn and a definite margin between border and text.
So i did:
void GETextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *widget = 0)
{
painter->drawRoundedRect(0, 0, boundingRect().width(),
boundingRect().height(), 5, 5);
QGraphicsTextItem::paint(painter, option, widget);
}
QRectF GETextItem::boundingRect()
{
const QRectF t = QGraphicsTextItem::boundingRect();
QRectF t2;
t2.setHeight(t.height()+20);
t2.setWidth(t.width()+20);
return t2;
}
QPainterPath GETextItem::shape() const
{
const QRectF t = QGraphicsTextItem::boundingRect();
QRectF t2;
t2.setHeight(t.height()+20);
t2.setWidth(t.width()+20);
QPainterPath path;
path.addEllipse(t2);
return path;
}
This draws the border (with margin) but if i move the item the 'bottom'
- the area outside the usual QGraphicsTextItem - is not redrawn (so
there are points left).
What am i doing wrong?
Thx for any help,
RZ
--
[ signature omitted ]
Message 3 in thread
thx - but why?!?!
maybe i am overlooking something obvious but in boundingRect() and
shape() there are the same lines:
const QRectF t = QGraphicsTextItem::boundingRect();
QRectF t2;
t2.setHeight(t.height()+20);
t2.setWidth(t.width()+20);
> Your bounding rectangle is smaller than the shape.
> The bounding rectt is used to find what has to be redrawn.
>
> -----Ursprüngliche Nachricht-----
> Von: RZ [mailto:rz@xxxxxxxxxxxx]
> Gesendet: Montag, 14. April 2008 15:38
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: Problem with QGraphicsTextItem
>
> Hi,
>
> i got a little problem regarding QGraphicsTextItem: i just want such an
> item with a border drawn and a definite margin between border and text.
>
> So i did:
>
> void GETextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
> *option, QWidget *widget = 0)
> {
> painter->drawRoundedRect(0, 0, boundingRect().width(),
> boundingRect().height(), 5, 5);
> QGraphicsTextItem::paint(painter, option, widget);
> }
>
> QRectF GETextItem::boundingRect()
> {
> const QRectF t = QGraphicsTextItem::boundingRect();
> QRectF t2;
> t2.setHeight(t.height()+20);
> t2.setWidth(t.width()+20);
> return t2;
> }
>
> QPainterPath GETextItem::shape() const
> {
> const QRectF t = QGraphicsTextItem::boundingRect();
> QRectF t2;
> t2.setHeight(t.height()+20);
> t2.setWidth(t.width()+20);
> QPainterPath path;
> path.addEllipse(t2);
> return path;
> }
>
> This draws the border (with margin) but if i move the item the 'bottom'
> - the area outside the usual QGraphicsTextItem - is not redrawn (so
> there are points left).
>
> What am i doing wrong?
>
> Thx for any help,
>
> RZ
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 4 in thread
And for answering my own problem:
the correct signature is
QRectF GETextItem::boundingRect() const
then everything works like a charme.
> Hi,
>
> i got a little problem regarding QGraphicsTextItem: i just want such an
> item with a border drawn and a definite margin between border and text.
>
> So i did:
>
> void GETextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
> *option, QWidget *widget = 0)
> {
> painter->drawRoundedRect(0, 0, boundingRect().width(),
> boundingRect().height(), 5, 5);
> QGraphicsTextItem::paint(painter, option, widget);
> }
>
> QRectF GETextItem::boundingRect()
> {
> const QRectF t = QGraphicsTextItem::boundingRect();
> QRectF t2;
> t2.setHeight(t.height()+20);
> t2.setWidth(t.width()+20);
> return t2;
> }
>
> QPainterPath GETextItem::shape() const
> {
> const QRectF t = QGraphicsTextItem::boundingRect();
> QRectF t2;
> t2.setHeight(t.height()+20);
> t2.setWidth(t.width()+20);
> QPainterPath path;
> path.addEllipse(t2);
> return path;
> }
>
> This draws the border (with margin) but if i move the item the 'bottom'
> - the area outside the usual QGraphicsTextItem - is not redrawn (so
> there are points left).
>
> What am i doing wrong?
>
> Thx for any help,
>
> RZ
--
[ signature omitted ]