Results 1 to 7 of 7

Thread: graphics view FitInView problem

  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question graphics view FitInView problem

    I am submitting a scaled down code of my application which has the fit in view problem.

    In CMainWindow constructor, I am calling FitInView() so that the contents of the view are fit to the viewport at the initial display. But this thing doesnt work. I checked the zoom level before and after the scene->views().first()->fitInView(rect,Qt::KeepAspectRatio);. They work correctly when FIV button is pressed from the main window, but not when FitInView is called from the CMainWindow constructor.

    When I press the FIV button after the main window is displayed, the contents are properly fitted onto the viewport.

    Why doesnt FitInView work properly in the constructor of the main window ?? Is it a bug or am I mising something ??
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: graphics view FitInView problem

    The geometry of a QWidget is calculated when it's show for the first time (unless forcing a fixed size). So sounds like a problem of undefined geometries..
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: graphics view FitInView problem

    So is there a way around to show the view fitted properly initially ??
    Even setting the view->setMinimumSize(), view->setMaximumSize() doesnt help.

    I had tried using a timer and it had worked. I used to set the timer to call FitInView, and after the first call, stop the timer.

    Is this timer solution fine, or can there be a better way around ?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: graphics view FitInView problem

    Quote Originally Posted by aamer4yu View Post
    I had tried using a timer and it had worked. I used to set the timer to call FitInView, and after the first call, stop the timer.
    You could also use QTimer::singleShot().

    Is this timer solution fine, or can there be a better way around ?
    I don't know about better, but just another option is to invoke fitInView() in the showEvent() of the main window, for example:
    Qt Code:
    1. void MainWindow::showEvent(QShowEvent* event)
    2. {
    3. QMainWindow::showEvent(event);
    4. static bool fitted = false;
    5. if (!fitted)
    6. {
    7. // put the fitInView() here..
    8. fitted = true;
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: graphics view FitInView problem

    the showevent is also not helping

    neways I did the workaround by the timer itself.... thx for the replies

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: graphics view FitInView problem

    I found another solution... though it gives same result as of usiing timer...

    in main function, call CMainWindow::FitInView() function, after mainWindow.showMaximised() call !!

    mainWindow.showMaximized();
    mainWindow.FitInView();



    but i prefer using the timer one, as it helps to keep the initialising things in the constructor .

  7. #7
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: graphics view FitInView problem

    Even I feel the timer approach is best. Actually I remember reading in KDE 3 development guide that most of the things regarding geometry of widget are better to be done in a slot and then using QTimer::singleShot().
    Last edited by Gopala Krishna; 25th January 2007 at 14:44. Reason: Removed irrelevant details
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. Graphics View or Paint ?
    By igor in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2007, 13:21
  2. which is better QCanvas or graphics view?
    By neomax in forum General Discussion
    Replies: 1
    Last Post: 23rd November 2006, 15:19
  3. Adding Rectangular overlay on graphics view
    By forrestfsu in forum Qt Programming
    Replies: 10
    Last Post: 21st November 2006, 19:42
  4. problem with tree view
    By boss_bhat in forum Newbie
    Replies: 4
    Last Post: 4th June 2006, 21:03
  5. View update problem
    By prakash in forum Qt Programming
    Replies: 6
    Last Post: 17th March 2006, 10:13

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.