Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Canvas problems

  1. #1
    Join Date
    Jan 2006
    Location
    Bend, Oregon
    Posts
    27
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Canvas problems

    Hi,

    I'm having problems with an application that uses the QCanvasView. My canvas items get distorted if another window covers them and then SLOWLY uncovers the items. This is especially pronounced when the view is zoomed. I created a minimal application that exhibits the problem (I'm using PyQt but you should be able to reproduce it with C++). I have also attached a screen shot of what I get when I move another window across my application. I have a feeling this is related to rounding errors of the world matrix transformation. Although I occasionally see these kind of problem when there is no transformation matrix involved.
    Maybe this has been fixed in a later version. I'm using Qt 3.3.1 on a Windows XP box.
    Please let me know if you can't reproduce this effect with a newer version.

    Thanks,
    Thomas

    Qt Code:
    1. import sys
    2. import qt
    3. import qtcanvas
    4.  
    5. class TMainWindow(qtcanvas.QCanvasView):
    6. def __init__(self, *args):
    7. qtcanvas.QCanvasView.__init__(self, *args)
    8.  
    9. oMatrix = qt.QWMatrix()
    10. oMatrix.scale(2, 2)
    11. self.setWorldMatrix(oMatrix)
    12. oRect = qtcanvas.QCanvasRectangle(20, 50, 100, 100, self.canvas())
    13. oRect.setBrush(qt.QBrush(qt.QColor('red')))
    14. oRect.show()
    15.  
    16. def closeEvent(self, e):
    17. oApp.quit()
    18.  
    19. oApp = qt.QApplication(sys.argv)
    20. canvas = qtcanvas.QCanvas(2000, 2000)
    21. oMainWindow = TMainWindow(canvas, None, 'Main Window')
    22. oMainWindow.show()
    23. oApp.exec_loop()
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Canvas problems

    i exactly dont know the syntax of Python but in terms of C++, i would like to know that why are you zooming it before creating the item on the canvas... wont it be correct for you to first draw the item and then zoom it...

    in C++ the code for the two would look like this.. my class is derived from the Q3CanvasView class...

    Qt Code:
    1. //creation of the Canvas Item
    2.  
    3. Q3Canvas *m_pCanvas = new Q3Canvas;
    4. setCanvas(m_pCanvas);
    5. m_pCanvas->setBackgroundColor(Qt::white);
    6. m_pCanvas->resize(1000,1000);
    7.  
    8. m_pCanvasRectangle = new Q3CanvasRectangle(10,10,20,20,m_pCanvas);
    9.  
    10. //for zooming it,
    11. QWMatrix m = worldMatrix();
    12. m.scale(2, 2 );
    13. setWorldMatrix( m );
    To copy to clipboard, switch view to plain text mode 

    this would do the things for you and also would execute pretty fast..
    in my case its instant fast whenever i am trying to zoom it...

    Kapil
    All you have to decide is what to do with the time that is given to you

  3. #3
    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: Canvas problems

    Are those objects which get distorted standard QCanvasObjects (like QCanvasLine) or did you subclass QCanvasItem (or one of its descendants) and implement your own object class? Because if the latter, the reason might be that an incorrect bounding rectangle is returned by the item.

  4. #4
    Join Date
    Jan 2006
    Location
    Bend, Oregon
    Posts
    27
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Canvas problems

    Thanks for the quick answers.

    The problem is not the zooming, it just exacerbates the problem, so I put it in the little sample program.

    The problem is not the bounding rectangle either, I stripped it down to the code listed in my initial post which uses a QCanvasRectangle with no subclassing whatsoever. The effects I see are not typical for an improperly set bounding rect either. It seems to be related to some kind of rounding or update error in the canvas view. It might be fixed in the current 3.3.6 version. If you can run the sample program and your application does not show these distortions most likely this has been fixed. I'm wondering if I should upgrade (which I probably won't if the bug still persists in 3.3.6).

    Cheers,
    Tommy

  5. #5
    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: Canvas problems

    But are those red lines the distorsions of the square? The square has black outline and the distorsions are red...
    Last edited by wysota; 8th May 2006 at 18:09.

  6. #6
    Join Date
    Jan 2006
    Location
    Bend, Oregon
    Posts
    27
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Canvas problems

    Probably, I played around with different versions so I get the biggest impact, one of them was with a red pen so the outline of the rect was red as well. I must have used that screenshot. In general it doesn't matter what shape or color you use this happens with all canvas items I have seen so far. There is a sample canvas app which has the same effect. Now maybe if it doesn't happen on your system and you run a newer version of Qt than 3.3.1 it might have been fixed in the mean time (I hope so).

    Tommy

  7. #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: Canvas problems

    I translated your app to C++ (see attachment). It doesn't show the artifacts you describe. If you resize the window, it shows some garbage, but not connected with the rectangle (see other attachment).
    Attached Images Attached Images
    Attached Files Attached Files

  8. #8
    Join Date
    Jan 2006
    Location
    Bend, Oregon
    Posts
    27
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Canvas problems

    Your C++ implementation looks like what I would have done. If you take another top level window and draw it "slowly" over the rectangle you don't see any distortions? Which version of Qt are you running? Maybe it is time for an upgrade. Thanks for your testing, that is really very helpful.

    Cheers,
    Thomas

  9. #9
    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: Canvas problems

    Quote Originally Posted by Tommytrojan
    If you take another top level window and draw it "slowly" over the rectangle you don't see any distortions?
    I do, but not connected with the rectangle (see attachment).

    Which version of Qt are you running?
    3.3.5
    Attached Images Attached Images

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Canvas problems

    Either I'm too fast or everything is OK on my system (PLD Linux, Qt 3.3.6, PyQt 3.15.1).

  11. #11
    Join Date
    Jan 2006
    Location
    Bend, Oregon
    Posts
    27
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Canvas problems

    Wow, that looks worse than what I came up with. Maybe this doesn't happen on Linux, I can see that there could be differences in this kind of behavior between Windows and Linux. So it looks to me as if 3.3.5 doesn't fix that problem.
    The question is if this is a Qt bug or if there is something that can be done on an API level to fix this problem. I have been looking into the setTranslationMode() function but both Point and Area have the same result.

    I'm surprised this has reported this problem before...


    Thanks,
    Thomas

  12. #12
    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: Canvas problems

    It's a problem with canvas refreshing. You'd probably have to update the canvas contents every time something obscures it. It's easier to upgrade to 3.3.6

  13. #13
    Join Date
    Jan 2006
    Location
    Bend, Oregon
    Posts
    27
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Canvas problems

    I would be happy to upgrade to 3.3.6 if the bug is fixed there. It seems your test with 3.3.5 still had the issue. I'm wondering if jacek could run his test with 3.3.6 on a Windows box. It might be that the problem is only Windows related and 3.3.6 doesn't fix it. Thanks again for looking into this issue.

    Cheers,
    Tommy

  14. #14
    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: Canvas problems

    Jacek doesn't have access to 3.3.6 under Windows Qt3 is available on Windows with a commercial licence only, while Qt3/Free port can provide its own bugs here and shouldn't be compared to the Trolltech version.

  15. #15
    Join Date
    Jan 2006
    Location
    Bend, Oregon
    Posts
    27
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Canvas problems

    So are there two versions? I currently use the commercial version of BlackAdder that comes with PyQt and Qt 3.3.1 (at least the release I have). I know that the Linux version of Trolltech has a GNU license, so is free if the software generated is open. Is there a version which is different from the Trolltech version?

    There is one more test that we could perform, if you could run your version (3.3.5) on a Linux box and the problem doesn't show up there it must be something in the difference of the Windows and Linux systems and most likely will not work on 3.3.6 for Windows either.

    Tommy

  16. #16
    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: Canvas problems

    You have seen my version. I get artifacts but other than you.

  17. #17
    Join Date
    Jan 2006
    Location
    Bend, Oregon
    Posts
    27
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Canvas problems

    I think what you have seen is typical for the kind of problem I have described, so I think we are looking at the same thing here. We know this does not happen on Linux with 3.3.6 but it does happen with 3.3.5 on Windows. We can't test 3.3.6 on Windows, so the only combination to test would be 3.3.6 (your version) on Windows if you have access to it. If not I will probably go ahead and purchase the commercial version from Trolltech. I currently have the commercial PyQt version which comes with a precompiled version of Qt 3.3.1.

    Tommy

  18. #18
    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: Canvas problems

    You can also switch to Qt 4

  19. #19
    Join Date
    Jan 2006
    Location
    Bend, Oregon
    Posts
    27
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Canvas problems

    Yeah, but since all my drawing code is based on the Q3 QCanvas I would have to use the Q3... classes anyway so there won't be a big difference in that regard.
    I hope Trolltech will implement a good/better paint engine in Q4 at some point. I need something that is highly efficient and has a simple interface like the QPainter interface.

    Tommy

  20. #20
    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

  21. The following user says thank you to wysota for this useful post:

    mhoover (10th May 2006)

Similar Threads

  1. problems creating toolbar...(do see the attachment)!
    By sumit in forum Qt Programming
    Replies: 15
    Last Post: 10th September 2008, 12:23
  2. flicker and wierd resize problems ...
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2008, 19:00
  3. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 22:28
  4. showMaximized doesnt show the canvas
    By Kapil in forum Qt Programming
    Replies: 5
    Last Post: 23rd May 2006, 13:22
  5. Setting focus on Canvas
    By Kapil in forum Qt Programming
    Replies: 10
    Last Post: 17th May 2006, 13:55

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.