Results 1 to 8 of 8

Thread: missing image with zoom (QGraphicsView)

  1. #1
    Join Date
    May 2006
    Posts
    57
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default missing image with zoom (QGraphicsView)

    Hi, everybody

    I have a problem with the zoom in the qgraphicsview, in my scene I have a square with a grid, when I scale the scene to view this square, but the qgraphicsview clear some areas of the image...

    I attach the code and put to image to show this error.

    P.D.I try use FullViewportUpdate



    With Zoom:
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: missing image with zoom (QGraphicsView)

    too much code for a simple grid item...

    But your CuadMesh::boundingRect has negative height causing exposure not being caught, change it to:

    Qt Code:
    1. QRectF CuadMesh::boundingRect() const
    2. {
    3. return QRectF( QPointF( -1, -101 ), QSizeF( 101, 101 ) );
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to lni for this useful post:

    avis_phoenix (16th March 2009)

  4. #3
    Join Date
    May 2006
    Posts
    57
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: missing image with zoom (QGraphicsView)

    How can I improve my code?? Thanks a lot

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: missing image with zoom (QGraphicsView)

    Quote Originally Posted by lni View Post
    But your CuadMesh::boundingRect has negative height causing exposure not being caught
    There is nothing wrong with negative height of the rectangle. You're just reversing the coordinate axis to point upwards instead of downwards. Of course one needs to know what (s)he is doing to use it, I don't know if that's the case here, but the bounding rect is fine.

    avis_phoenix: You don't need all those delete statements in the destructor. Read about memory management in Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: missing image with zoom (QGraphicsView)

    Quote Originally Posted by wysota View Post
    There is nothing wrong with negative height of the rectangle.
    You lost me, what does a rectangle with a negative height look like? Can you give an example that works in QGraphicsItem with negative height in its boundingRect? Also, you said his boundingRect is fine, then how do u fix his problem?

  7. #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: missing image with zoom (QGraphicsView)

    I havent seen the code, but for improving it, you might try drawing the grid in drawBackGround function of view/scene ..

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: missing image with zoom (QGraphicsView)

    Quote Originally Posted by lni View Post
    You lost me, what does a rectangle with a negative height look like?
    It's Y axis points upwards not downwards probably, as already written, by the way...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #8
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: missing image with zoom (QGraphicsView)

    Quote Originally Posted by avis_phoenix View Post
    How can I improve my code?? Thanks a lot
    Let me try to see if I can provide some "peer review" feedback. But people may have different opinion though..

    If someone feels he has to spend more than 10 seconds to understand your code, he would most likely to turn away quickly. That is why those who answer your post doesn't really provide a real fix other than making some general comments, not because they don't know how to fix it. I look at your codes, and the only part I spent time on is CuadMesh::boundingRect, becasue it is only 1 line of code.

    The use of QPainterPath along with so many moveTo and lineTo in the constructor is really difficult to understand. Try not to write too many things in constructor becasue of C++'s metamorphism...

    I think you will not add other objects in CuadMesh class, right? If so, the codes would become even more unreadable and unusable in other places. If you add a banana in it, then I can't use it if I want to plot a cat with same grid. With that, I suggest to rename your class to CuadGridItem2D to be explicit, because when I unzip your codes, the first thing I did was looking for a *.h file with either "grid" or "item" in the file name, I didn't find it, so I have to open all the *.h files..

    I add "2D' because you mix X-grid and Y-grid in the same class. What if I want X grid to be logarithmic and Y grid to be linear? What if I only want to have X grid and not Y grid? So, I would split it into CuadXGridItem and CuadYGridItem, and make a base class CuadGridItem. I am sure you are going to write more C++, with that, you can reuse the codes in many different projects on different requirements.

    On CuadGridItem, you implement paint method by setting up pen and color, etc, and make a pure virtual "drawGridLine", and let XGrid and YGrid to implement how to draw, where XGrid draws in X direction, and YGrid draws in Y direction...

    OO design is like marriage. In Houston where I live as well as in most other places, it works great to have a Marriage class where you define a marriage to be between a male and a female, but this class doesn't work in California...

Similar Threads

  1. image on qgraphicsview
    By aj2903 in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2009, 12:34
  2. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  3. how to draw lines on image using QGraphicsView in Qt4
    By madhavilatha in forum What's New in Qt 4.4
    Replies: 1
    Last Post: 25th July 2008, 00:32
  4. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  5. no image displayed on QGraphicsView
    By sincnarf in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2007, 12:33

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.