1 Attachment(s)
problem in positioning item in QGraphicsScene()
hi friends,
i have a problem in positioning an rect item (0, 0, 20, 150) in a graphicsScene() of size (0, 0, 1024, 1024)
Code:
DiagView
::DiagView(QWidget *parent
)
{
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setCacheMode(CacheBackground);
setViewportUpdateMode(FullViewportUpdate);
setStyleSheet("background:#336699");
QRectF bounds
(0,
0,
1024,
1024);
setScene(scene);
item1
= new SlotItem
(QRectF(0,
0,
20,
150));
item1->setPos(10,180);
scene->addItem(item1);
}
{
fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
}
slotitem.cpp
Code:
SlotItem
::SlotItem(const QRectF &rect
){
}
{
painter
->setBrush
(QColor(0,
102,
153));
painter->drawRoundRect(rect());
}
QRectF SlotItem
::boundingRect() {
}
main.cpp
Code:
int main(int argc, char *argv[])
{
DiagView *dialog = new DiagView();
dialog->setGeometry(0, 0, 1024, 1024);
dialog->show();
return app.exec();
}
but the SlotItem is shown in the center of the view port because of the resize event .. if i dont use resize event it positioned the item acurately ... but i need the resize event in future ... what went wrong in my code .. please any one help me ...
Re: problem in positioning item in QGraphicsScene()
I'm a bit confused. First you pass a rectangle to the QGraphicsRectItem constructor but then you reimplement boundingRect() and return a different rectangle. What's the point of doing that? The two rectangles should be identical.
About your problem - try changing the aspect parameter of the fitInView call.
Re: problem in positioning item in QGraphicsScene()
sorry i will change soon the bounding rect value ....
sir in my view i set the geometry to (1024, 1024) and QGraphicsScene also has the same and i positioned the item and it works correctly ... i reimplement the resize event then now the item displayed in centre when i use setPos(0, 30) in my scene .... please help ...
Re: problem in positioning item in QGraphicsScene()
Please read my post again.
Re: problem in positioning item in QGraphicsScene()
try changing the aspect parameter of the fitInView call.
thanks ... i will