PDA

View Full Version : Canvas problems



Tommytrojan
8th May 2006, 03:06
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


import sys
import qt
import qtcanvas

class TMainWindow(qtcanvas.QCanvasView):
def __init__(self, *args):
qtcanvas.QCanvasView.__init__(self, *args)

oMatrix = qt.QWMatrix()
oMatrix.scale(2, 2)
self.setWorldMatrix(oMatrix)
oRect = qtcanvas.QCanvasRectangle(20, 50, 100, 100, self.canvas())
oRect.setBrush(qt.QBrush(qt.QColor('red')))
oRect.show()

def closeEvent(self, e):
oApp.quit()

oApp = qt.QApplication(sys.argv)
canvas = qtcanvas.QCanvas(2000, 2000)
oMainWindow = TMainWindow(canvas, None, 'Main Window')
oMainWindow.show()
oApp.exec_loop()

Kapil
8th May 2006, 07:41
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...



//creation of the Canvas Item

Q3Canvas *m_pCanvas = new Q3Canvas;
setCanvas(m_pCanvas);
m_pCanvas->setBackgroundColor(Qt::white);
m_pCanvas->resize(1000,1000);

m_pCanvasRectangle = new Q3CanvasRectangle(10,10,20,20,m_pCanvas);

//for zooming it,
QWMatrix m = worldMatrix();
m.scale(2, 2 );
setWorldMatrix( m );



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

wysota
8th May 2006, 10:25
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.

Tommytrojan
8th May 2006, 16:01
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

wysota
8th May 2006, 17:58
But are those red lines the distorsions of the square? The square has black outline and the distorsions are red...

Tommytrojan
8th May 2006, 18:08
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

wysota
8th May 2006, 18:10
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).

Tommytrojan
8th May 2006, 18:15
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

wysota
8th May 2006, 18:18
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

jacek
8th May 2006, 18:55
Either I'm too fast or everything is OK on my system (PLD Linux, Qt 3.3.6, PyQt 3.15.1).

Tommytrojan
8th May 2006, 22:43
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

wysota
9th May 2006, 00:25
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 :)

Tommytrojan
9th May 2006, 00:32
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

wysota
9th May 2006, 00:37
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.

Tommytrojan
9th May 2006, 00:42
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

wysota
9th May 2006, 01:07
You have seen my version. I get artifacts but other than you.

Tommytrojan
9th May 2006, 02:13
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

wysota
9th May 2006, 03:08
You can also switch to Qt 4 :)

Tommytrojan
9th May 2006, 03:33
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

wysota
9th May 2006, 11:41
http://blogs.qtdeveloper.net/archives/2006/05/01/a-graphicsview-sneak-peek/

Tommytrojan
9th May 2006, 16:41
Wow, that is great news. I'm certain that problem will be fixed in the new implementation. Does anyone know when a beta of 4.2 will become available?

Tommy

wysota
9th May 2006, 16:53
Q3-Q4/2006.

BTW. Jacek suggested that you might have understood that I have tested your code with Qt 3.3.5 under Windows -- that's not true, I tested it under Linux, I don't have Qt 3.3 for Windows.

Tommytrojan
9th May 2006, 17:46
Well, if you tested under Linux and the problem showed up with your 3.3.5 version and Jacek tested with the 3.3.6 version and it didn't show there is a chance that it was resolved in between these two releases. I will upgrade in the next few weeks and send a reply to what I find regarding this problem.

Cheers,
Tommy