0
我希望圖形場景能夠顯示覆蓋整個圖像的圖像。我創建具有相同大小的場景的圖像,但得到這樣的結果:在Qt整個QGraphicsScene上顯示圖像
可否請你所說的其實是錯誤的代碼?謝謝
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QGraphicsPixmapItem * image = new QGraphicsPixmapItem(QPixmap("C:\\data\\99.png"));
int imageWidth = image->pixmap().width();
int imageHeight = image->pixmap().height();
image->setOffset(- imageWidth/2, -imageHeight/2);
image->setPos(0, 0);
QGraphicsScene *scene = new QGraphicsScene();
scene->setSceneRect(-imageWidth/2, -imageHeight/2, imageWidth, imageHeight);
QGraphicsView * gv = new QGraphicsView();
ui->gridLayout->addWidget(gv);
gv->setScene(scene);
qInfo()<<"width image " <<imageWidth; // 640
qInfo()<<"height image " <<imageHeight; // 400
qInfo()<<"width scene " <<scene->width(); // 640
qInfo()<<"height scene " <<scene->width(); // 400
gv->scene()->addItem(image);
gv->show();
}
非常感謝這麼快速的回答! – Zheden