Cairo and Qt integration

11,014

Solution 1

Starting from cairo 1.17.8, the Qt support will be removed upstream.

Old answer

Recent version of cairo supports Qt by allowing to draw to a surface created with cairo_qt_surface_create(QPainter *painter): you can inspect the relevant header file here. There's no documentation because this feature is still experimental and disabled by default (you should compile cairo yourself explicitely enabling the Qt support with configure --enable-qt.

Solution 2

Qt's Paint System is a very good drawing library and is vector based. And it's already there. If you pick Qt as your GUI toolkit, it can't get any easier.

Solution 3

Caveat: This is not going to be the answer you are looking for.

Are you sure you want this? To what end? Is this about writing a QPaintDevice based on Cairo? Qt has its own graphics primitives implemented and so does Cairo. The only reason I can see is that you don't want the a heavy layer of Qt interfere with your system (embedded?). It's like you are trying to use the DirectFB backend of Cairo -- but then there's stuff like Qt-on-DirectFB. However, note such an implementation is costly and not free without its own set of quarks such as library-interop issues, printing from this Cairo based context etc. I'd suggest you do a regular search on Google to figure if such efforts are/ever were underway and weigh the pros and cons very heavily before even attempting the same.

Solution 4

It can be achieved by this dirty way:

  1. Create an cairo image surface, draw on that surface.
  2. Call cairo_image_surface_get_data() to get the pixels.
  3. Copy the image to a Qt widget.
Share:
11,014
Andrei
Author by

Andrei

Updated on June 01, 2022

Comments

  • Andrei
    Andrei about 2 years

    I want to use Cairo graphics library whith Qt, but I can't find any documenattion. I just want to make the GUI whith Qt and use Cairo for drawing graphics in a Qt window.

    Thanks.