2
ui->setupUi(this);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
//scene->setSceneRect(-200,-200,300,300);
//ui->graphicsView->setRenderHint(QPainter::Antialiasing);

QPixmap pic (":/Single_linked_list.png");
//pic.load(":/Single_linked_list.png");
QGraphicsPixmapItem *item = new QGraphicsPixmapItem (/*pic*/);
item->setPixmap(pic);
scene->addPixmap(pic);

scene->addItem(item);
scene->
// scene->show();

//painter.drawPixmap(/*scene->sceneRect().bottomLeft().x()+0.1*/0.10,/* scene->sceneRect().bottomLeft().y()-0.1*/0.10, pic);

上記は、グラフィックアイテムに画像を追加するための私のコードです。グラフィックシーンは表示されていますが、何をしてもpixmap/pixmapitemは表示されていません。何が問題になっていますか?どうすれば修正できますか?

また、そのイメージをさらにアニメーション化するつもりです。グラフィックシーンのこれ、picmapまたはpixmapアイテムに最適なコンテナはどれですか?

4

2 に答える 2

1

指定されたリソースで QPixmap オブジェクトが適切に初期化されたかどうかを確認します。これを行うには、QPixmap::isNull() を呼び出します。null の場合は、適切に初期化されておらず、問題はリソースです。

于 2012-12-18T17:55:57.423 に答える
0

Your scene setup seems fine. You can check if your scene works properly by adding QGraphicsRectItem at any desired position on the scene.

Adding pixmap to your existing scene -

QGraphicsPixmapItem *newItem=new QGraphicsPixmapItem(QPixmap(":/Single_linked_list.png"));
scene->addItem(newItem);

This will add the pixmap item to the scene as well as show it. You don't need to call it explicitly to show the image.

If you want to apply normal animations like translation, rotation or scaling, you can simply use the setPos, setScale or setTransform functions. For better control, you can use Animation Framework provided by Qt. It applies to any QGraphicsItem i.e. also QGraphicsPixmapItem. Check out the documentation for more reference.

Take a look at this video for Qt GraphicsView basics - http://www.youtube.com/watch?v=b35JF4LqtBs and check this link for simple QGraphicsItem animation - http://www.youtube.com/watch?v=fmSs2mNGh9I

于 2012-12-15T18:52:27.893 に答える