I am having trouble displaying an image (or anything) in a QGraphicsView
I have a frame named mainwindow which contains simply a QGraphicsView widget named mainGraphics
I have an image named imageMap.bmp which I have added to the resource file
When I run the program, the QGraphicsView mainGraphics is blank.... just a white space in the frame..... if I change the setSceneRect param, the scrollable area does change size, so I am def changing parameters on the correct item, but just none of the graphics will show up...???
The code in mainwindow.cpp is as follows:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
ui->mainGraphics->setSceneRect(0,0,500,500);
QPixmap back
(":/images/imageMap.bmp");
ui->mainGraphics->setBackgroundBrush(back);
scene.addText("Some text");
scene.addLine(10,10,200,200);
ui->mainGraphics->setScene(&scene);
ui->mainGraphics->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->mainGraphics->setSceneRect(0,0,500,500);
QPixmap back(":/images/imageMap.bmp");
ui->mainGraphics->setBackgroundBrush(back);
QGraphicsScene scene;
scene.addText("Some text");
scene.addLine(10,10,200,200);
ui->mainGraphics->setScene(&scene);
ui->mainGraphics->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
a file named main.cpp contains the main() function which starts the program
Bookmarks