So, anyone can help me?
Regarding your x position, why are you not setting it to half of the width like you did with the height?:
Qt Code:
int x = - this->vrptr->geometry().width()/2;To copy to clipboard, switch view to plain text mode
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
ok, so now as you see, the scroll bar is not appearing any more (your original problem).
So the only thing you have to do now is to figure out the correct position coordinates, such, that you don't position your strings outside the visible scene area and all is well.
EDIT:
it looks like the scene is larger then your QGraphicsView, which makes the center of the scene more to the right of the viewing area.
Resize the scene to the size of the viewing area, and then
Qt Code:
int x = - this->vrptr->geometry().width()/2;To copy to clipboard, switch view to plain text mode
should work.
Last edited by high_flyer; 16th October 2009 at 17:32.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Andrewshkovskii (19th October 2009)
The incorrect coordinates/position was my problem first![]()
either because of no knowledge of English, either because of stupidity, I can not understand your 2nd sentence) You mean,what i pos my string outside the the visible scene first time?But what i need to do, to solve the problem with position strings at upper lefr corner?M.b i need to set QGraphicsView::setSceneRect to View's rect? or something else?
oh...so setSceneRect, as i think,will solve my problem ,yeath?
if i do like this :
Qt Code:
{ this->visualResultModel->setSceneRect(this->vrptr->rect()); int x = - (this->vrptr->geometry().height()/2); int y= - (this->vrptr->geometry().height()/2); QGraphicsItem * item; static int yGrow = fn.height() -3; this->visualResultModel->clear(); item= visualResultModel->addText(model->horizontalHeaderItem(0)->text(),font); item->setPos(x,y); for(int i=1;i<size;++i) { item= visualResultModel->addText(model->horizontalHeaderItem(i)->text(),font); item->setPos(x,y+yGrow); y=item->pos().y(); } }To copy to clipboard, switch view to plain text mode
That's what happens
i.e items pos() out of viewport area
I think you need to re-thinking your item management, since you seems to not use graphics features as usual way.
QGraphicsView is a view of a QGraphicsScene.
When unsing QGraphicsItem::setPos, you are positionning item in the scene as data regarless of the view portion of the scene displayed in the view.
So the point(0,0) is the center of the scene, whatever shows the view.
To put your item at topleft corner of the view, you can use QGraphicsView::mapToScene to convert pixel coordinates of the viewport to scene coordinates. see the-graphics-view-coordinate-system
But if you dont move the view, every item will be at same position!
But this still not explain why your sceneRect grows in y-axis...
Bookmarks