PDA

View Full Version : View,Scene and RectItem



salmanmanekia
29th March 2010, 07:24
i have a very basic problem ,i am trying to draw a rectangle in my widget at a certain position but it wont draw ,below is the code ,

aWidget::aWidget(QWidget *parent)
: QWidget(parent)
{

....
matrixScene = new QGraphicsScene();
matrixView = new QGraphicsView(matrixScene);
DrawMatrix();
..
}
void aWidget::DrawMatrix()
{
squares.setRect(1000,1000,50,50);
//squares = new QGraphicsRectItem();
//squares = matrixScene.addRect(QRectF(10,50,100,100));
matrixScene->addItem(&squares);
matrixView->setScene(matrixScene);
}
#include <QtGui>
#include <QWidget>
#include "ui_ninesilicawidget.h"

class aWidget : public QWidget
{
Q_OBJECT
...
QGraphicsView *matrixView;
QGraphicsScene *matrixScene;
QGraphicsRectItem squares;
Ui::NineSilicaWidgetClass ui;
..
...
};

#endif // NINESILICAWIDGET_H

aamer4yu
29th March 2010, 07:42
Is your sceneRect set properly ? May be the item is too far away and its not being drawn ?
Also about the design, why dont you inherit from QGraphicsView itself ?

Ohh wait.. where did you show the view ??? :rolleyes:

zgulser
29th March 2010, 14:31
Is your sceneRect set properly ?

More likely the problem is about this issue..