PDA

View Full Version : Having trouble with QGraphicsView



mrwooster
11th August 2009, 09:23
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)
: 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;
}


a file named main.cpp contains the main() function which starts the program

wagmare
11th August 2009, 10:09
may be the scene is obscuring the background image of the view ... make QGraphicsScene little transperent using setOpacity() ..

also use QGraphicsView::setCacheMode(CacheBackground);

mrwooster
11th August 2009, 10:48
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....

wagmare
11th August 2009, 10:59
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 ..

mrwooster
11th August 2009, 11:14
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