Domanda

Come impostare la trasparenza di un / schermo rettangolare.

Ho seguente codice:

// main.cpp
void main(int argc, char*[] argv)
{
    QApplication::setGraphicsSystem("raster");
    QApplication app(argc, argv);

    QDeclerativeView 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();
}

E file QML è:

//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;
    }
}

Ho un caricatore e una sola immagine in questa schermata e il colore di sfondo è trasparente. Quando faccio funzionare questa applicazione dovrebbe visualizzare sfondo trasparente con immagine al centro (come non ho impostato fonte loader).

ma quello che sto ottenendo è l'immagine nel centro con sfondo bianco pieno nella schermata, non so chi sta riempiendo in questo colore di sfondo bianco, come ho accennato colore trasparente come sfondo.

Sto usando QT.4.7.0 e Linux.

Ho due piani sul mio sistema di destinazione si è piano video e un altro è piano grafica, quando ho eseguito GUI con sfondo trasparente (trasparenza insieme a casa video) dovrebbe visualizzare video su Video posto nell'esempio di sopra di essa sta mostrando come sfondo bianco, come avrebbe dovuto visualizzata la riproduzione di video sul piano del video.

È stato utile?

Soluzione

By default the QDeclarativeView paints a background. Maybe that's the problem in your case.

From http://doc.qt.nokia.com/4.7/qdeclarativeperformance.html

You can also prevent QDeclarativeView from painting its window background if you will provide the background of your application using QML, e.g.

 QDeclarativeView window;
 window.setAttribute(Qt::WA_OpaquePaintEvent);
 window.setAttribute(Qt::WA_NoSystemBackground);
 window.viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
 window.viewport()->setAttribute(Qt::WA_NoSystemBackground);

Altri suggerimenti

My first guess is that the background is white and your rectangle is indeed fully transparent.

What type is LoaderScreen, I guess it is some sort of QDecalarativeView, please forgive any technical misses have not coded Qt/QML for almost a year now. As I remember it the default background of the view was white and what kind of transparency are you hoping to achive anyways?

If you only set a background-color on a QPushButton, the background may not appear unless you set the border property to some value. This is because, by default, the QPushButton draws a native border which completely overlaps the background-color. This might show a black rectangular box around QPushButton. You will face this issue especially on Linux machines. In order to avoid this you can set the border property to none

widget->setStyleSheet("border:none");

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top