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