当前位置:编程学习 > wap >>

Qt中QGraphicsView QGraphicsScene QGraphicsRectItem的问题

#include <QtGui/QApplication>

#include <QGraphicsView>
#include <QGraphicsRectItem>
#include <QGraphicsScene>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QGraphicsView v;
    v.setGeometry(300, 200, 800, 480);

    v.show();
    QGraphicsScene *scene = new QGraphicsScene();
    scene->setSceneRect(0, 0, 800, 480);
    v.setScene(scene);

    QGraphicsRectItem *item = new QGraphicsRectItem(200, 0, 400, 400, 0, scene);
    item->setBrush(QBrush(QColor(255, 0, 0)));
    QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, 100, 100, item, 0);
    item1->setBrush(QBrush(QColor(255, 255, 0)));
    
    return a.exec();
}

代码中,我明明为item1指定了item为它的父item,为什么显示的时候item1还是显示在了场景的(0, 0)位置,而不是item上的(0, 0)位置。如果调用item->hide();item1也会跟着消失,说明父item是设置成功了,但是显示为什么是这样?  --------------------编程问答-------------------- 为什么没有人回答? --------------------编程问答-------------------- item默认的原点都在scene的原点,如果需要改变原点,要自己手动修改。 --------------------编程问答--------------------
引用 1 楼 panrongtao1 的回复:
为什么没有人回答?

回答你的问题不是义务,更不是责任,只是乐于助人的精神。 --------------------编程问答-------------------- 郁闷中。。。。。 --------------------编程问答-------------------- 没人回答么,也在等这个问题。 --------------------编程问答--------------------
void QGraphicsItem::setPos(const QPointF & pos)
补充:移动开发 ,  Qt
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,