PDA

View Full Version : QGraphicsTextItem dont open Link /bug?



patrik08
7th July 2007, 11:17
Why QGraphicsTextItem dont open link? is this a bug?

or is here other method to append QGraphicsTextItem to scene?

a minimal build main.cpp is attach here.



/* load central widget */
void Load_Connector()
{
view = new QGraphicsView(this); /* QMainWindow */
Vbar = view->verticalScrollBar();
Hbar = view->horizontalScrollBar();
QGraphicsScene *scene = new QGraphicsScene(view);
scene->setSceneRect( 0, 0, 1000, 1000 );
view->setScene(scene);
setCentralWidget(view);
/* set tag xhtml to projekt xml tag */
QString qthtml = "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;\"><span style=\" font-family:'Impact'; font-size:26pt; color:#5555ff;\">H</span>"
"<span style=\" font-family:'Impact'; font-size:26pt; color:#0000ff;\">e</span>"
"<span style=\" font-family:'Impact'; font-size:26pt; color:#ff0000;\">l</span>"
"<span style=\" font-family:'Impact'; font-size:26pt; color:#ffff00;\">l</span>"
"<span style=\" font-family:'Impact'; font-size:26pt; color:#ffaa7f;\">o</span>"
"<span style=\" font-family:'Impact'; font-size:26pt;\"> </span>"
"<span style=\" font-family:'Impact'; font-size:26pt; color:#00ff00;\">color</span>"
"<span style=\" font-family:'Impact'; font-size:26pt; color:#ff0000;\"> world</span>"
"<span style=\" font-family:'Impact'; font-size:26pt;\">!</span>"
"<a href=\"http://wiki.qtcentre.org/index.php?title=QGraphicsTextItem\"><span style=\" text-decoration: underline; color:#0000ff;\">link</span></a> </p> ";

QGraphicsTextItem* txtarea = scene->addText("");
txtarea->setHtml(qthtml);
txtarea->setOpenExternalLinks(true); /* set clickable */
txtarea->setFlag(QGraphicsItem::ItemIsMovable);
ViewPoint(0); /* scroll area stay 0 to init! */
}

jpn
7th July 2007, 11:51
txtarea->setTextInteractionFlags(Qt::LinksAccessibleByMouse ); // | Qt::LinksAccessibleByKeyboard

patrik08
7th July 2007, 12:58
txtarea->setTextInteractionFlags(Qt::LinksAccessibleByMouse ); // | Qt::LinksAccessibleByKeyboard


OK .. tanks i found ... but is not possibel to make it ItemIsMovable and
Qt::TextBrowserInteraction on same modus? i must split modus to
view edit preview , correct or is this mistake?





QGraphicsTextItem* txtarea = new QGraphicsTextItem(0,scene);
txtarea->setHtml(qthtml);
txtarea->setOpenExternalLinks(true); /* set clickable */
////txtarea->setTextInteractionFlags(Qt::TextEditorInteraction) ;
txtarea->setTextInteractionFlags(Qt::TextBrowserInteraction );
txtarea->setFlag(QGraphicsItem::ItemIsMovable);
txtarea->ensureVisible(QRectF(10,10,200,200),80,80);
txtarea->moveBy(100,200);

jpn
7th July 2007, 13:22
but is not possibel to make it ItemIsMovable and
Qt::TextBrowserInteraction on same modus?
Well, setting Qt::TextBrowserInteraction makes the item to handle mouse move events as selection. You should still be able to move the item by grabbing from its edges.

patrik08
9th July 2007, 10:16
Now i have adjusted and it paint correct ..
but ..

setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);

stay on old place... why?

how i can handle ItemIsMovable area?



QRectF boundingRect() const
{
/*
int width; html div area
int hight; html div area
moveBy(GetInt("left"),GetInt("top"));
*/
QRectF now = QGraphicsTextItem::boundingRect(); /* actual setting */
return QGraphicsTextItem::boundingRect().adjusted(-2,-2, width - now.width() , hight - now.height() );
}