我的QGraphicsView出了点问题。我已经将QGraphicsView子类化以重新定义paintEvent。我想用QGraphicsItem表示节点,用QGraphicsLineItem表示边,画出一棵树。
void GraphicsView::paintEvent ( QPaintEvent * event ) {
if(arbre!=NULL) {
arbre->line1->setLine(arbre->text->x(),arbre->text->y(),
arbre->text1->x(),arbre->text1->y());
QGraphicsView::paintEvent(event);
cout << "redessine" << endl;
}}
有什么建议可以去掉这些吗?
发布于 2012-03-26 03:59:31
请确保在QGraphics*Item子类的boundingRect()方法中包含页边距。
http://qt-project.org/doc/qt-4.8/qgraphicsitem.html#boundingRect
PS:不要把逻辑放在paintEvent方法中。此方法用于呈现内容,而不是收集UI字段内容或其他内容(arbre->line1->setLine)
发布于 2015-03-02 18:30:49
除了放错位置的逻辑之外,在改变对象几何形状之前,调用QGraphicsItem::prepareGeometryChange()。
https://stackoverflow.com/questions/9859974
复制相似问题