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::setGraphicsSystem("raster");
    QApplication app(argc, argv);

    QDeclarativeView view;
    view.setSource(QUrl::fromLocalFile("loaderTest.qml"));
    
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
    view.showFullScreen();
    
    //QRegion mask(10, 10,  100, 100);
    //view.setMask();
    
    view.show();
    app.exec();
    

    }
    @

    And QML file is:

    @
    //loaderTest.qml
    Rectangle
    {
    id: mainRectangle
    width: 1000
    height: 700
    color: "transparent"
    //color: "#00000000"

    Image
    {
        id: image1;
        width: 348;
        height: 155;
        anchors.horizontalCenter: parent.horizontalCenter;
        anchors.verticalCenter: parent.verticalCenter;
        source: "test.png"
    }
    
    Loader
    {
        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.

    Thanks.



  • 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.setWindowFlags(Qt::FramelessWindowHint);
    view.setAttribute(Qt::WA_TranslucentBackground);
    view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view.setStyleSheet("background: transparent");
    view.setFrameStyle(QFrame::NoFrame);
    @

    [EDIT: code formatting, Volker]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.