PDA

View Full Version : Problems when QGraphicsScene is larger than QGraphicsView



lukabratzi
28th August 2010, 15:39
Hey all,

I'm working at making a program to display a directed graph read from a file. I don't know how large the graph will be, so I'd like to make the scene dynamic and for the view to be a fixed size. I implemented a custom class ZoomView based on QGraphicsView. The only added functionality that it has is the ability to zoom in and out and to be able to drag the view around different parts of the scene.

I was able to get it to work with a fixed scene size, but that won't do for my final project. Right now I calculate the size in my calculateSize function and base the size of my scene and other widgets on that. The only sizes that are actually fixed are the main window (DiagramWindow) and the view. I believe the issue lies in my call to view->setGeometry but I don't know why.

Is there any way to fix this so that I can have a larger scene than view? Is it even possible?

Thanks.


DiagramWindow::DiagramWindow()
{
readFile(allResources, sortedResources);
int* sizeCount = new int[allResources.size()];
for(int k1 = 0; k1 < allResources.size(); k1++)
sizeCount[k1] = 0;
int xSize = 0, ySize = 0;
calculateSize(allResources, sizeCount, xSize, ySize);

centralWidget = new QWidget(this);
scene = new QGraphicsScene(0, 0, xSize, ySize);

view = new ZoomView(centralWidget);
view->setScene(scene);
view->setRenderHints(QPainter::Antialiasing
| QPainter::TextAntialiasing);

view->setContextMenuPolicy(Qt::ActionsContextMenu);

lineEdit = new QLineEdit(centralWidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(15, 515, 530, 20));
view->setGeometry(15, 515, 530, 20);

setCentralWidget(centralWidget);

minZ = 0;
maxZ = 0;
seqNumber = 0;

createActions();
createMenus();
createToolBars();

connect(scene, SIGNAL(selectionChanged()),
this, SLOT(updateActions()));

connect(lineEdit, SIGNAL(returnPressed()),
this, SLOT(on_lineEdit_returnPressed()));

setWindowTitle(tr("Diagram"));
setFixedWidth(600);
setFixedHeight(600);
updateActions();

draw();
}

Lykurg
28th August 2010, 15:57
normally the scene is larger then the view - at least in my projects. Make sure you set the right policy for your scroll bars and Qt will handle the rest for you. If you change something in your scene set the new screen size by calling QGraphicsScene::itemsBoundingRect(). Also better use layouts then setGeometry.

lukabratzi
28th August 2010, 16:26
The scroll bars were working perfectly before, so I don't know if thats the issue. I just can't get the view to appear in my window now that I've added the call to view->setGeometry

lukabratzi
28th August 2010, 17:10
I fixed it. Thanks for the help though, no more early morning coding for me unless i have enough coffee to make sure i'm intelligent