Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Transparency for an rectangle is not working.
Forum Updated to NodeBB v4.3 + New Features

Transparency for an rectangle is not working.

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 7.2k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    at_pradeep
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

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

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • A Offline
        A Offline
        at_pradeep
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • T Offline
          T Offline
          task_struct
          wrote on last edited by
          #4

          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.

          "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

          • Linu...
          1 Reply Last reply
          0
          • A Offline
            A Offline
            at_pradeep
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              manishsharma
              wrote on last edited by
              #6

              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]

              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