Results 1 to 4 of 4

Thread: Problems when QGraphicsScene is larger than QGraphicsView

  1. #1

    Default Problems when QGraphicsScene is larger than QGraphicsView

    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.

    Qt Code:
    1. DiagramWindow::DiagramWindow()
    2. {
    3. readFile(allResources, sortedResources);
    4. int* sizeCount = new int[allResources.size()];
    5. for(int k1 = 0; k1 < allResources.size(); k1++)
    6. sizeCount[k1] = 0;
    7. int xSize = 0, ySize = 0;
    8. calculateSize(allResources, sizeCount, xSize, ySize);
    9.  
    10. centralWidget = new QWidget(this);
    11. scene = new QGraphicsScene(0, 0, xSize, ySize);
    12.  
    13. view = new ZoomView(centralWidget);
    14. view->setScene(scene);
    15. view->setRenderHints(QPainter::Antialiasing
    16. | QPainter::TextAntialiasing);
    17.  
    18. view->setContextMenuPolicy(Qt::ActionsContextMenu);
    19.  
    20. lineEdit = new QLineEdit(centralWidget);
    21. lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    22. lineEdit->setGeometry(QRect(15, 515, 530, 20));
    23. view->setGeometry(15, 515, 530, 20);
    24.  
    25. setCentralWidget(centralWidget);
    26.  
    27. minZ = 0;
    28. maxZ = 0;
    29. seqNumber = 0;
    30.  
    31. createActions();
    32. createMenus();
    33. createToolBars();
    34.  
    35. connect(scene, SIGNAL(selectionChanged()),
    36. this, SLOT(updateActions()));
    37.  
    38. connect(lineEdit, SIGNAL(returnPressed()),
    39. this, SLOT(on_lineEdit_returnPressed()));
    40.  
    41. setWindowTitle(tr("Diagram"));
    42. setFixedWidth(600);
    43. setFixedHeight(600);
    44. updateActions();
    45.  
    46. draw();
    47. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Problems when QGraphicsScene is larger than QGraphicsView

    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.

  3. #3

    Default Re: Problems when QGraphicsScene is larger than QGraphicsView

    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

  4. #4

    Default Re: Problems when QGraphicsScene is larger than QGraphicsView

    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

Similar Threads

  1. QGraphicsScene & QGraphicsView help please
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 13th February 2017, 12:30
  2. Replies: 0
    Last Post: 29th September 2009, 02:28
  3. QGraphicsView and QGraphicsScene
    By alisami in forum Qt Programming
    Replies: 8
    Last Post: 4th December 2008, 10:10
  4. QGraphicsScene/QGraphicsView performance problems
    By bnilsson in forum Qt Programming
    Replies: 71
    Last Post: 28th January 2008, 12:08
  5. QGraphicsScene and QGraphicsView
    By rossd in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2007, 14:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.