Having trouble with QGraphicsView
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:
Code:
#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;
}
a file named main.cpp contains the main() function which starts the program
Re: Having trouble with QGraphicsView
may be the scene is obscuring the background image of the view ... make QGraphicsScene little transperent using setOpacity() ..
also use QGraphicsView::setCacheMode(CacheBackground);
Re: Having trouble with QGraphicsView
I have set the cach mode to cachBackground but it still doesn't make any difference.... nothing is showing up....
Also, the QGraphicsScene does not have a setOpacity() function, that is only implemented by QGraphicsItem.....
I don't think it is an opacity issue as even the text and line is not showing up....
Re: Having trouble with QGraphicsView
if not setOpacity() then alpha value u can set in QColor ()
ok did u see the padnavigator example ... they set pixmap for the graphicsView ... see where the problem arise ..
Re: Having trouble with QGraphicsView
I really appreciate your help wagmare, but unfortunaltely I am still having problems...
I have had a look through the padnavigator example but I dont see where I have implemented it any different apart from the fact that they made a subclass of QGraphicsView...
Also... if I remove the QGraphicsScene element, it still does not show a background.... so its not an opacity problem