views:

164

answers:

2

I'm starting using Qt in my application. My application is MFC based. I want to draw some QGraphicsItems in my currect MFC view, is it possible?

You may say that it could be done by hosting QGraphicsView with QWinWidget in the MFC view, that don't work, however. Because my Canvas (MFC view) supports zooming and rotating while the QGraphicsView itself don't. When I zooming the QGraphicsItem, the QGraphicsView shows scroll bar instead of enlarging itself.

Any suggestion? Thanks!

A: 

Theoretically you could use QGraphicsScene::paint to paint the scene with your QGraphicsItems in the buffer, and then draw it to MFC view, but it does not make any sense...

What is the problem with QGraphicsView anyway? Have you taken a look at the rotate(), scale(), translate() or shear() functions of it?

ak
The QGraphicsView is actually an QWidget. When I scale it to a large size, it scales its content (QGraphicsScene) and shows scroll bar itself. When I rotate it, it rotates its content also rather than itself.What I really want is the QGraphicsTextItem. I want to show it in the MFC view, and when I zoom the canvas or rotate the canvas in 3d view, the text should zoom or rotate also. And I can also edit the text in the canvas.Is that possible to make QGraphicsView have that ability? Make it no border and adjust itself along its content (QGraphicsScene)?
Kevin C.
A: 

You can turn off the displaying of scroll bard of QGraphicsView by setting the ScrollBarPolcies to Qt::ScrollBarAlwaysOff. (QGraphicsView is a sub-class of QAbstractScrollArea.)

I am not sure I understand what you mean by rotating QGraphicsView itself instead of the content. Without the scroll bars, I don't see the difference. Also much of the functionality of QGraphicsItem like editing as you indicated, depends on event handling in QGraphicsScene and QGraphicsView to work. I don't think plugging just a QGraphicsItem into the MFC view will do what you want.

Stephen Chu
I may need to make the QGraphicsView occupy the whole canvas and make it translucent. As you said, without QGraphicsView, the editing functionality may lose also. Thanks.
Kevin C.