Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Draw in QDesktopWidget (Desktop-Background)

    General and Desktop
    3
    13
    830
    Loading More Posts
    • 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
      rsadowski last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • R
          rsadowski @mrjj last edited by

          @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."

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @rsadowski last edited by

            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 Reply Quote 0
            • R
              rsadowski last edited by

              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.

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @rsadowski last edited by

                @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 Reply Quote 1
                • R
                  rsadowski last edited by

                  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 Reply Quote 1
                  • R
                    rsadowski last edited by

                    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

                    mrjj 1 Reply Last reply Reply Quote 1
                    • mrjj
                      mrjj Lifetime Qt Champion @rsadowski last edited by

                      @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 Reply Quote 0
                      • R
                        rsadowski last edited by

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

                        mrjj 1 Reply Last reply Reply Quote 0
                        • mrjj
                          mrjj Lifetime Qt Champion @rsadowski last edited by

                          @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 Reply Quote 0
                          • Christian Ehrlicher
                            Christian Ehrlicher Lifetime Qt Champion last edited by

                            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

                            mrjj 1 Reply Last reply Reply Quote 1
                            • mrjj
                              mrjj Lifetime Qt Champion @Christian Ehrlicher last edited by

                              @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 Reply Quote 0
                              • First post
                                Last post