Solved Widget with custom paintEvent is not drawing
-
I am the maintainer of XaoS. It has an optional Qt GUI, whose source is here. I have a custom FractalWidget that overrides paintEvent to draw a QImage, whose pixel buffer XaoS directly writes into. This code used to work under Qt4 and I believe earlier versions of Qt5 as well. Actually, it still works in Windows, but in Linux, the widget just stays black. (I am running Ubuntu 18.04, using the included Qt 5.9 libraries) I also have a different code path using paintGL, which still works, and I can enable by defining USE_OPENGL in my code. However, I want to get the standard paintEvent working as well in case users have ancient graphics cards that don't do Open GL well.
Can someone take a look at my code and tell me what I'm doing wrong? If there are any questions about the code I will try to answer them.
-
Hi and welcome to devnet,
Where are you filling these QImages from ?
-
XaoS has a system of pluggable filters, each of which writes directly to the pixel buffers The filters are in a queue, and each filter modifies the pixel buffer based on the output of the previous filter. Eventually, once all the filters have had a pass, the image is drawn on screen. There is an image struct which contains pointers to the pixel buffers, and info such as the width, height, row stride, R/G/Bmasks, and so forth. The create_image_cont function creates the image struct with the pixel buffer created by the QImage. It is called here and takes its information about the image format from the ui_driver structure defined here. The most important of the filters is the zoom filter that does the actual fractal calculation. The line of code where the zoom filter actually writes to the buffer is here.
It's all pretty complicated, but all you really need to know is that various filters write to the buffers based on the width, height, stride, and R/G/B mask defined in the ui_driver struct. This abstraction makes XaoS flexible and has allowed it to be ported to many different APIs with minimal effort, on systems as diverse as Xlib, Windows, Mac OS X, GTK+, Qt, even DOS.
I'm pretty sure the problem is not with the contents of the pixel buffer, because the code works on all the other systems, as well as on earlier versions of Qt, and even Qt 5 on windows. It's just on Linux with Qt 5.9 that it doesn't work.
-
It was because I had set
Qt::WA_PaintOnScreen
on my widget. Removing that fixed the problem.