Tom Leese
Tom Leese

Reputation: 19679

Making a window a desktop in XLib/Qt

I am trying to write a simple program to act as my desktop background in Qt, I have made it all work fine apart from making it a Desktop Widget. I have no idea on how to do this, I don't mind using XLib or Qt for doing this, but if anyone has some suggestions I would be very happy.

Upvotes: 5

Views: 1026

Answers (1)

mtvec
mtvec

Reputation: 18316

I have created a simple example that will fill the desktop background white. It is easy to make it draw an image.

class DesktopWidget : public QWidget
{
        Q_OBJECT

    public:

        DesktopWidget()
        {
            setAttribute(Qt::WA_X11NetWmWindowTypeDesktop);
            resize(QApplication::desktop()->size());
        }

    protected:

        void paintEvent(QPaintEvent*)
        {
            QPainter painter(this);
            painter.fillRect(geometry(), Qt::white);
        }
};

The problem with this solution is that it completely paints over everything that your desktop environment draws in the background (including icons, plasmoids,...).

If you just want to set a new background image programmatically, I would check if your DE has an API for that.

Upvotes: 3

Related Questions