October 19, 2011

toho71 toho71
Lab Rat
189 posts

[SOLVED]Graphicsview how to

 

Hello
I’m trying to use the graphicsview and graphics scene.
Only a simpel test to build from but even this doesn’t work

I use qt desigener and puts the g_view on the mainwindow and I’m trying to set the scene in the constructor.

But nothing happens.
Here is some code.

  1. m_graphScen = new QGraphicsScene(this);
  2.     m_graphScen->setSceneRect(0,0,790,290);
  3.     m_graphScen->addText("Hello, world!");
  4.     // a blue background
  5.     m_graphScen->setBackgroundBrush(Qt::blue);
  6.  
  7.     // a gradient background
  8.     QRadialGradient gradient(0, 0, 10);
  9.     gradient.setSpread(QGradient::RepeatSpread);
  10.     m_graphScen->setBackgroundBrush(gradient);
  11.  
  12.     QPainterPath path;
  13.     path.moveTo(10, 30);
  14.     path.cubicTo(80, 0, 50, 50, 80, 80);
  15.  
  16.     m_graphScen->addPath(path, QPen(Qt::black), QBrush(Qt::green));
  17.  
  18.     m_graphScen->addText("Hello, world!", QFont("Times", 10, QFont::Bold));
  19.  
  20.  
  21.     ui->m_graphView->setFixedSize(800,300);
  22.     ui->m_graphView->setScene(m_graphScen);
  23.     ui->m_graphView->setBackgroundBrush(Qt::blue);

The problem wasn’t here.
It was the calling to this method that was the problem

0 replies

 
  ‹‹ [solved] Different layout on item in" listview      QGraphicsEffect: difference between drawing source in logical and device coordinates ››

You must log in to post a reply. Not a member yet? Register here!