Results 1 to 4 of 4

Thread: strange QGraphicsView sizing behavior

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default strange QGraphicsView sizing behavior

    I have created a main window with a QGraphicsView and worked it such that when the window is resized, the scene will remain in the window and scale itself to always fit within the QGraphicsView no matter what size it is. I used the following method to do this:

    Qt Code:
    1. WindowScene::WindowScene(QWidget *parent) : QMainWindow(parent) {
    2.  
    3.  
    4.  
    5. setupUi(this);
    6. database = db;
    7.  
    8. cview = new QGraphicsView;
    9. cview->installEventFilter(this);//set event filter
    10.  
    11. setCentralWidget(cview);
    12.  
    13. cscene = new QGraphicsScene;
    14. populateScene(); //put some junk in the scene for testing
    15.  
    16. cview->setScene(cscene);
    17.  
    18. createDockWindows();
    19. //add dock widget to the side
    20.  
    21.  
    22.  
    23. }
    24.  
    25. bool WindowScene::eventFilter(QObject *o, QEvent *e) {
    26. //process resize event of needed widget
    27. if (o == cview && e->type() == QEvent::Resize) {
    28. //rescale the scene to fit the view
    29. cscene->views().first()->fitInView(cview->sceneRect().toRect(),Qt::KeepAspectRatio);
    30. return true;
    31. }
    32. return QMainWindow::eventFilter(o, e);
    33. }
    To copy to clipboard, switch view to plain text mode 

    This seems to work for the most part, but there is a strange issue where the scene will not show up when I drag the window in certain ways:

    - If I expand the window to the side only, then the scene scaling works perfect
    - If I expand the window to up and down only then the scene scaling works perfect.
    - If I make the window smaller in the vertical and horizontal directions at the same time, the scene scales down.
    - If I make the window larger vertically and horizontally at the same time, then the scene moves, centered with the window, but the viewport does not expand and the scaling stops short of where it should in order to fill the viewable area.

    What might be causing this issue only when enlarging the window in both directions at same time? I have attached pictures so you can see what it is doing
    Attached Images Attached Images

Similar Threads

  1. Replies: 0
    Last Post: 9th September 2008, 12:57
  2. Very strange behavior of QWidget in Qt Designer
    By THRESHE in forum Qt Programming
    Replies: 10
    Last Post: 13th August 2008, 16:19
  3. Strange QTcpSocket behavior (debugged with Ethereal)
    By mdecandia in forum Qt Programming
    Replies: 23
    Last Post: 28th May 2007, 20:44
  4. Strange behavior with Drag and Drop (not always drops)
    By Mona Shokrof in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2007, 18:00
  5. QComboBox +SUSE10.0 +qt4.1 strange behavior
    By antonio.r.tome in forum Qt Programming
    Replies: 6
    Last Post: 20th March 2006, 17:49

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.