Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Draw in QDesktopWidget (Desktop-Background)

Draw in QDesktopWidget (Desktop-Background)

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rsadowski
    wrote on last edited by
    #1

    Hallo Qt Community,

    I'm trying to port an old Qt3 open-source application to Qt5. It is an application that overdraws the desktop background with a bitmap.
    It is an application that overdraws the desktop background. Unfortunately nothing is drawn. Even if I just give the widget a different color. Nothing to see.

    the main:

    int main(int argc, char** argv)
    {
        MyApp app(argc, argv);
        app.init();
        return app.exec();
    }
    

    and MyApp:

    MyApp::MyApp(int &argc, char **argv)
        : QApplication(argc, argv)
    {
    }
    
    
    void MyApp::init()
    {
        timer = new QTimer(this);
    
        connect(timer, SIGNAL(timeout()), this, SLOT(recalc()));
        QTimer::singleShot(1, this, SLOT(recalc()));
        timer->start(delay * 1000);
    }
    
    void MyApp::recalc()
    {
            QRect  screenGeometry = desktop()->geometry();
            const int height = screenGeometry.height();
            const int width = screenGeometry.width();
            qInfo() << "Desktop geometry height: " << height << " width: " << width;
    
            QPalette palette;
            palette.setBrush(desktop()->backgroundRole(),  QBrush(*(getMyQImage())));
            desktop()->setPalette(palette);
            desktop()->show();
            //XClearWindow(QX11Info::display(), QX11Info::appRootWindow());
    }
    

    Everything works fine. recalc() is always called, but unfortunately nothing is drawn.

    Do I have a thank you error somewhere? Target system is Linux. Did I miss something?

    Thanks for all your help.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What is desktop() ? a QDesktopWidget ?

      Does it have a paintEvent and does it do anything special to
      " overdraws the desktop background" compared to just being a normal
      (borderless) widget that is working as an overlay ?

      Also in qt3 i believe you could do something like

         QPainter paint( QApplication::desktop()->screen( 0 ), true );
          paint.draw...
          ...
          paint.end();
      

      But not sure that will actually still work even if it compiles.

      R 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        What is desktop() ? a QDesktopWidget ?

        Does it have a paintEvent and does it do anything special to
        " overdraws the desktop background" compared to just being a normal
        (borderless) widget that is working as an overlay ?

        Also in qt3 i believe you could do something like

           QPainter paint( QApplication::desktop()->screen( 0 ), true );
            paint.draw...
            ...
            paint.end();
        

        But not sure that will actually still work even if it compiles.

        R Offline
        R Offline
        rsadowski
        wrote on last edited by
        #3

        @mrjj Thanks for your quick reply, as you can see below, yes desktop() the static function from QApplication

        QDesktopWidget *QApplication::desktop()
        
        Returns the desktop widget (also called the root window).
        
        The desktop may be composed of multiple screens, so it would be incorrect, for example, to attempt to center some widget in the desktop's geometry. QDesktopWidget has various functions for obtaining useful geometries upon the desktop, such as QDesktopWidget::screenGeometry() and QDesktopWidget::availableGeometry().
        
        On X11, it is also possible to draw on the desktop.
        

        So I thought it would be a good place for drawn something. "On X11, it is also possible to draw on the desktop."

        mrjjM 1 Reply Last reply
        0
        • R rsadowski

          @mrjj Thanks for your quick reply, as you can see below, yes desktop() the static function from QApplication

          QDesktopWidget *QApplication::desktop()
          
          Returns the desktop widget (also called the root window).
          
          The desktop may be composed of multiple screens, so it would be incorrect, for example, to attempt to center some widget in the desktop's geometry. QDesktopWidget has various functions for obtaining useful geometries upon the desktop, such as QDesktopWidget::screenGeometry() and QDesktopWidget::availableGeometry().
          
          On X11, it is also possible to draw on the desktop.
          

          So I thought it would be a good place for drawn something. "On X11, it is also possible to draw on the desktop."

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Ok so you subclassed QDesktopWidget ?

          Hmm yes, . "On X11, it is also possible to draw on the desktop." does sounds like it works on linux.

          Did you try to give it a paintevent ?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rsadowski
            wrote on last edited by
            #5

            Okay, perhaps I was misunderstood. It's no longer an Qt3 application! So QPainter is not an option in Q5:
            QWidget::paintEngine: Should no longer be called.

            "Ok so you subclassed QDesktopWidget ?" You can see in my first code-block, that's all. I inherit from "QApplication", get the desktop and try to draw inside like in the code above. This isn't working, any idea? I need something to cover the desktop background. I thought the QDesktopWidget from QApplication was just the thing, unfortunately no.

            mrjjM 1 Reply Last reply
            0
            • R rsadowski

              Okay, perhaps I was misunderstood. It's no longer an Qt3 application! So QPainter is not an option in Q5:
              QWidget::paintEngine: Should no longer be called.

              "Ok so you subclassed QDesktopWidget ?" You can see in my first code-block, that's all. I inherit from "QApplication", get the desktop and try to draw inside like in the code above. This isn't working, any idea? I need something to cover the desktop background. I thought the QDesktopWidget from QApplication was just the thing, unfortunately no.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @rsadowski
              Well you may only use QPainter in the PaintEvent function unless drawing to an image.
              So thats is most likely the reason for that error.

              Im not really sure how one would draw with it. Let me test and see if i can get a result.

              1 Reply Last reply
              1
              • R Offline
                R Offline
                rsadowski
                wrote on last edited by
                #7

                Thanks for your efforts. This post describes what I want to do but I looks outdated for me:

                https://stackoverflow.com/questions/42645876/qt5-drawing-on-x11-root-screen-and-changing-the-wid-of-an-existing-qwidget

                Looking in https://doc.qt.io/qt-5/qx11info.html#appRootWindow it referents to https://doc.qt.io/qt-5/qapplication.html#desktop which sounds like "QApplication::desktop()" should give me the root widget (desktop).

                1 Reply Last reply
                1
                • R Offline
                  R Offline
                  rsadowski
                  wrote on last edited by
                  #8

                  I thought it should work, but it doesn't:

                  auto d = QWidget::createWindowContainer(QWindow::fromWinId(QX11Info::appRootWindow())); 
                  

                  but it only creates a new Window and not draw on the X11 desktop. I found an smeller post here:

                  https://lists.qt-project.org/pipermail/interest/2017-March/026304.html

                  mrjjM 1 Reply Last reply
                  1
                  • R rsadowski

                    I thought it should work, but it doesn't:

                    auto d = QWidget::createWindowContainer(QWindow::fromWinId(QX11Info::appRootWindow())); 
                    

                    but it only creates a new Window and not draw on the X11 desktop. I found an smeller post here:

                    https://lists.qt-project.org/pipermail/interest/2017-March/026304.html

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @rsadowski
                    Hi
                    I tested various things i found on google and nothing did draw on the desktop. ( linux mint, Xfce )
                    I wonder if docs are wrong or it is indeed still possible.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      rsadowski
                      wrote on last edited by
                      #10

                      I come to the same conclusion. Should I create a ticket?

                      mrjjM 1 Reply Last reply
                      0
                      • R rsadowski

                        I come to the same conclusion. Should I create a ticket?

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @rsadowski
                        Yes that would be a good idea. At least we need to change the docs if its really possible anymore
                        or there are requirements to the windows manager etc.
                        Its best if you include a sample so its easy to test for the developers.

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Online
                          Christian EhrlicherC Online
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          QDesktopWidget is deprecated - don't know if it's worth the trouble.

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          mrjjM 1 Reply Last reply
                          1
                          • Christian EhrlicherC Christian Ehrlicher

                            QDesktopWidget is deprecated - don't know if it's worth the trouble.

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @Christian-Ehrlicher

                            Oh Thanks, i missed "This class is obsolete." in the docs.
                            I agree it's unlikely it will be looked at.

                            Also, so far none of the method one can google worked so it might not be possible anymore with
                            Qt alone.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved