Qtで簡単なMandlebrotビューアを作成しようとしていますが、メインウィンドウにQGraphicsSceneがあり、Qimageに画像を生成してから、QMainWindowでQGraphicsSceneを更新するには
私は最初の画像を表示することができますが、私は座標を変更した後に再レンダリングする方法がわかりません。 私の人生の中で、私はQMainWindowをリフレッシュする方法、あるいはMainWindowからQGraphicsSceneを削除し、それをレンダリングするための呼び出しを行う方法を考えることができません。
QImage renderImage(//loads in global variables)
{
//calculates the image and returns a QImage
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QGraphicsScene *graphic = new QGraphicsScene(this);
graphic->addPixmap(QPixmap::fromImage(renderImage()));
ui->graphicsView->setScene(graphic);
}
void MainWindow::on_Left_clicked()
{
// Changes global variables and try to rerender the scene.
update(); //does nothing
}
UPDATE:解決! たくさんの助けをしてくれてありがとう、ありがとう。私はQtが新しくなっているので、ループがどこを更新するのかは分からなかった。あなたが提案したコードを追加したところ、完全に機能しました。ありがとう:)
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QGraphicsScene *graphic = new QGraphicsScene(this);
pixmap_item = graphic->addPixmap(QPixmap::fromImage(renderImage()));
ui->graphicsView->setScene(graphic);
}
void MainWindow::on_Left_clicked()
{
// Changes global variables and try to rerender the scene.
centerR -= 0.1;
pixmap_item->setPixmap(QPixmap::fromImage(renderImage()));
}
彼はQGraphicsViewを持っています。これはUI定義にあり、コンストラクターで正しく設定されています。 – goug