Results 1 to 3 of 3

Thread: Painting on screen

  1. #1
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Painting on screen

    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.

  2. #2
    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: Painting on screen

    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.

  3. #3
    Join Date
    Feb 2006
    Posts
    31

    Default Re: Painting on screen

    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.

    Qt Code:
    1. if X11
    2. x11Disp = QPaintDevice::x11AppDisplay();
    3. x11Screen = QPaintDevice::x11AppScreen();
    4. x11Rootw = QPaintDevice::x11AppRootWindow();
    5.  
    6. long gcflags;
    7. XGCValues gcv;
    8. gcv.foreground = 100000;
    9. gcv.function = GXcopy;
    10. gcv.subwindow_mode = IncludeInferiors;
    11. gcflags = GCForeground | GCFunction | GCSubwindowMode;
    12.  
    13. //X11 GC
    14. x11GC = XCreateGC(x11Disp, x11Rootw, gcflags, &gcv);
    15.  
    16. XColor fg;
    17.  
    18. fg.red = (int)((float)color.red() * 65535.0 / 255.0);
    19. fg.green = (int)((float)color.green() * 65535.0 / 255.0);
    20. fg.blue = (int)((float)color.blue() * 65535.0 / 255.0);
    21.  
    22. //X11 Colormap
    23. x11Colormap = QPaintDevice::x11AppColormap(x11Screen);
    24.  
    25. XAllocColor(x11Disp, x11Colormap, &fg);
    26. XSetForeground(x11Disp, x11GC, fg.pixel);
    27.  
    28. XDrawRectangle(x11Disp, x11Rootw, x11GC, x, y, w, h);
    29. XFlush(x11Disp);
    30.  
    31. else if WIN32
    32. QPainter p(QApplication::desktop());
    33. m_currPen.setColor(color);
    34. p.setPen(m_currPen);
    35. p.drawRect(x, y, w, h);
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 6th January 2009 at 19:08. Reason: missing [code] tags

Similar Threads

  1. Creating a Screen Saver for Windows
    By spud in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2011, 15:58
  2. Paint streaming pixel data
    By jmsbc in forum Qt Programming
    Replies: 4
    Last Post: 23rd September 2008, 04:15
  3. Using QGraphicsView as a Splash Screen (repaint issues)
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2008, 21:22
  4. Setting manually cursor position on multi screen systems
    By irreriwan in forum Qt Programming
    Replies: 0
    Last Post: 4th March 2008, 09:47
  5. multi screen
    By Thomas Feldman in forum Qt Programming
    Replies: 5
    Last Post: 9th May 2007, 16:41

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.