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();
}
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();
}