How to use QGraphicsVeiw

35 views Asked by At

I need to create a application,which is created in QMainWindow. I have created application.in UI form I have dragged QGraphicsView. I have created Graphic scene also. I'm posting the code.i'm able to get scene but it by deafult coming at topleft corner. other than coming inside QGraphicsView.suggest me,where I might have gone wrong.

#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
     QApplication a(argc, argv);
     MainWindow w;
     w.show();
    return a.exec();
}

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QBrush>


 namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();

protected:
void changeEvent(QEvent *e);

 private:
Ui::MainWindow *ui;
 };

#include "mainwindow.h"
#include "ui_mainwindow.h"

 MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
 ui(new Ui::MainWindow)
 {
   ui->setupUi(this);

   QGraphicsView *view = new QGraphicsView(this);
   QGraphicsScene *scene=new QGraphicsScene();
   scene->setBackgroundBrush(Qt::red);
   view->setScene(scene);

   }

  MainWindow::~MainWindow()
 {
   delete ui;
  }

  void MainWindow::changeEvent(QEvent *e)
  {
  QMainWindow::changeEvent(e);
   switch (e->type()) {
   case QEvent::LanguageChange:
      ui->retranslateUi(this);
      break;
   default:
      break;
   }
   }

Please suggest me.Thanks in advance

0

There are 0 answers