PDA

View Full Version : Painting on screen



Alex_123
2nd January 2009, 22:52
Hi. Could someone tell me if it's possible to paint on screen using Qt? I mean to paint without having a widget. I'm going to use it on Linux and MacOS. Thanks in advance.

wysota
2nd January 2009, 22:53
There is no "screen" :) You probably mean the desktop, right? No, Qt doesn't allow it. You can only place a transparent widget over the desktop and paint on that. Although on KDE4 the desktop is a Qt4 widget, it's in a separate application, so you can't paint on it.

oob2
6th January 2009, 19:00
this is code in Qt3 to draw a rect with QColor color;
since you are drawing on the desktop, this rect can be easily erased by any other image
events from your desktop.


if X11
x11Disp = QPaintDevice::x11AppDisplay();
x11Screen = QPaintDevice::x11AppScreen();
x11Rootw = QPaintDevice::x11AppRootWindow();

long gcflags;
XGCValues gcv;
gcv.foreground = 100000;
gcv.function = GXcopy;
gcv.subwindow_mode = IncludeInferiors;
gcflags = GCForeground | GCFunction | GCSubwindowMode;

//X11 GC
x11GC = XCreateGC(x11Disp, x11Rootw, gcflags, &gcv);

XColor fg;

fg.red = (int)((float)color.red() * 65535.0 / 255.0);
fg.green = (int)((float)color.green() * 65535.0 / 255.0);
fg.blue = (int)((float)color.blue() * 65535.0 / 255.0);

//X11 Colormap
x11Colormap = QPaintDevice::x11AppColormap(x11Screen);

XAllocColor(x11Disp, x11Colormap, &fg);
XSetForeground(x11Disp, x11GC, fg.pixel);

XDrawRectangle(x11Disp, x11Rootw, x11GC, x, y, w, h);
XFlush(x11Disp);

else if WIN32
QPainter p(QApplication::desktop());
m_currPen.setColor(color);
p.setPen(m_currPen);
p.drawRect(x, y, w, h);