1 Attachment(s)
How draw extra border on QGraphicsTextItem?
Code:
/*
incomming QDomElement
<divtext rotate="90" zindex="2" left="115" top="25" large="300" hight="400" >
<param font="arial" color="#0000ff" size="30">Scribble XHTML Floating DIV box width:300px height:400px top:25px left:115px</param>
</divtext>
*/
{
Q_OBJECT
public:
{
modus = MODUS_MOVE;
root = xmlstream;
moveBy(GetInt("left"),GetInt("top"));
rotate(GetInt("rotate"));
int FontSize = root.firstChildElement("param").attributeNode("size").value().toInt();
if (FontSize > 9) {
f.setPixelSize(FontSize);
} else {
f.setPixelSize(10);
}
f.setFamily( root.firstChildElement("param").attributeNode("font").value() );
setDefaultTextColor ( root.firstChildElement("param").attributeNode("color").value() );
human = root.firstChildElement("param").text();
setTextWidth ( GetInt("large") );
setPlainText ( human );
setFont(f);
setZValue( GetInt("zindex") + 300 ); /* to make border - */
SetMoveItem();
QObject::connect(scene,
SIGNAL(selectionChanged
()),
this,
SLOT(WakeUpHere
()));
/////// ensureVisible(QRectF(GetInt("left"),GetInt("top"),GetInt("large"),GetInt("hight")),80,80);
}
{
painter->drawRect (-2,-2,GetInt("large") + 4,8); /* GetInt("hight") + 4 border 2px out side overflow*/
update();
}
1 Attachment(s)
Re: How draw extra border on QGraphicsTextItem?
I not make forward paint :o ..
but now ony resize window display a correct border why?
Code:
{
pen.setStyle( Qt::SolidLine );
pen.setWidth( 2 );
pen.setColor( option->palette.highlight().color() );
/////scene()->clearSelection();
////prepareGeometryChange();
painter->setPen( pen);
painter->drawRect (-2,-2,GetInt("large") + 4,GetInt("hight") + 4);
}
Re: How draw extra border on QGraphicsTextItem?
All painting must be restricted to inside an item's bounding rect.
Re: How draw extra border on QGraphicsTextItem?
Quote:
Originally Posted by
jpn
All painting must be restricted to inside an item's
bounding rect.
If i set setTextWidth(300); his paint only on this area ... and text break on this limit correct.
Now i must grab a way to become setTextHight(x) to display text only on this limit, like xhtml div overflow / hidden http://de.selfhtml.org/css/eigenscha...g.htm#overflow
inside moveBy(10,10); and how i find the way to increase the bounding width whitout destroy textwidht pixel ?
I not find SetboundingRect(X) area ... and margin? to increase this paint area? to make my border and limit text Width x Hight.
Re: How draw extra border on QGraphicsTextItem?
You need to override boundingRect() to return enlarged rect. I did some sample code.
This worked for me for all rotations and pixel sizes. Here it is.
Guess this is what you wanted
Code:
#include <QtGui>
{
//Q_OBJECT;
public:
{
setPlainText ( "human ");
f.setPixelSize(40);
setFont(f);
rotate(-90);
}
{
}
{
// Isn't this strange to call update in paint event ?
//update();
painter->setPen(Qt::black);
painter->drawRect(boundingRect());
}
};
int main(int argc, char *argv[])
{
FloatText t(&scene);
t.setPos(500,500);
view.show();
return app.exec();
}