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. How to create a TransparentWindow, using Qt5, with QtQuick1

How to create a TransparentWindow, using Qt5, with QtQuick1

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 1.6k Views
  • 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.
  • W Offline
    W Offline
    weiyuemin
    wrote on last edited by
    #1

    I'm now using Qt5, but for some reasons I want to use QtQuick1, because there are some problems in my program when using QtQuick2.(mainly because of OpenGL)

    But eventually I still faced problems using QtQuick1. If I set Qt::WA_TranslucentBackground to a QDeclarativeView, the program crashes when executing at app->exec(). My Code is:

    @
    #include <QtWidgets/QApplication>
    #include <QtDeclarative/qdeclarative.h>
    #include <QtDeclarative/qdeclarativeview.h>

    int main(int argc, char *argv[])
    {
    QScopedPointer<QApplication> app(new QApplication(argc, argv));

    QDeclarativeView view;
    view.setSource(QUrl::fromLocalFile("main.qml"));
    QPalette palette = view.palette();
    palette.setColor(QPalette::Base, Qt::transparent);
    view.setPalette(palette);
    //view.setStyleSheet("background:transparent"); //uncomment this line will make the whole window invisible
    //view.setAttribute(Qt::WA_TranslucentBackground); //uncomment this line will make the program crash
    view.setWindowFlags(Qt::FramelessWindowHint);

    view.show();

    return app->exec();
    }
    @

    And my QML file(main.qml):
    @
    import QtQuick 1.1

    Rectangle {
    width: 600
    height: 400
    color: "transparent"
    Image {
    source: "some_pic.png" //it is less than 600 * 400
    }
    }
    @

    My system is Win Xp. Similar code works well when I'm using Qt4.8..

    Any ideas? Thank you :)

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danut.iurascu
      wrote on last edited by
      #2

      I have test your example using Qt5 on Ubuntu, and I have no issue to compile and run such a implementation.
      @viewer.setStyleSheet("background:transparent");
      viewer.setAttribute(Qt::WA_TranslucentBackground);@
      are working fine for me.

      regards,
      Dănuț

      1 Reply Last reply
      0
      • D Offline
        D Offline
        diorahman
        wrote on last edited by
        #3

        What is we use QGLWidget as viewport. It will be failed

        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