Important: Please read the Qt Code of Conduct -

Transparency for an rectangle is not working.

  • How to set transparency of an rectangle/screen.

    I have Following code:

    @// main.cpp
    void main(int argc, char*[] argv)
    QApplication app(argc, argv);

    QDeclarativeView view;
    //QRegion mask(10, 10,  100, 100);


    And QML file is:

    id: mainRectangle
    width: 1000
    height: 700
    color: "transparent"
    //color: "#00000000"

        id: image1;
        width: 348;
        height: 155;
        anchors.horizontalCenter: parent.horizontalCenter;
        anchors.verticalCenter: parent.verticalCenter;
        source: "test.png"
        id: mainLoader
        anchors.fill: parent;
        source: "";
        focus: true;


    I have one loader and one image in this screen and background color is transparent.
    When i run this application it should display transparent background with image in the center (as i have not set loader source).

    but what i am getting is image in center with white background filled in the screen, I don't know who is filling in this white background color as i have mentioned transparent color as background.

    I am using QT.4.7.0 and Linux.


  • The white color comes from LoaderScreen. Rectangle is transparent, but widget behind it is not. So you see LoaderScreen widget.

  • I have updated the source to "QDeclarativeView" but still the result is same. Is it "QDeclarativeView" which is filling the white background color??

  • Yes. Rectangle is just an item drawn on QDeclarativeView. It does not tell QDeclarativeView to be transparent. If you want your application to be transparent see how to set QWidget's background transparency.

  • Thank for the reply, I tried to set the LoaderScreen background to transparent in the constructor,
    using "setAttribute(Qt::WA_TranslucentBackground)" and using
    "QWidget::setBackgroundMode(Qt:NoBackground);" but it is of no use, still i am getting white background. can some one please tell me how to set background to transparent.

  • How abt below setup??

    QDeclarativeView view;
    view.setStyleSheet("background: transparent");

    [EDIT: code formatting, Volker]

Log in to reply