Qt, QML, ColorImage non è un tipo di

0

Domanda

Ho fatto un QML componente pulsante e ho usato un componente denominato ColorImage per l'icona. Dopo la ricerca di un modo per cambiare il colore dell'immagine. Ho scoperto che Qt non supportano più ColorOverlay

Hover, ho scritto nel "colore" in Qt e Studio di Progettazione ColorImage spuntato. Ho provato a trovare la documentazione online, ma non ho trovato nulla. Tuttavia, quando ho deciso di provare, funziona come mi aspettavo:

Questo è il codice in questione dal mio pulsante:

    contentItem: ColorImage {
        id: buttonIcon
        source: imageSource
        fillMode: Image.PreserveAspectFit
        height: parent.height
        color: iconColor
        anchors.fill: actionBarButton
        anchors.margins: 4
    }

Quando il hovered stato del pulsante diventa true permette la seguente stato:

State {
            when: (hovered && !checked)
            name: "hoveredNotChecked"
            PropertyChanges {
                target: buttonIcon
                color: "white"
            }

            PropertyChanges {
                target: buttonBackground
                color: iconColor
            }
        },

riporti, l'icona e il colore di sfondo del pulsante.

Questo funziona in anteprima il Qt Designer. Tuttavia, quando si tenta di eseguire da Pyside, mi dice: ColorImage is not a type e semplicemente non riesce a caricare il pulsante.

Ho provato a trovare la documentazione di ColorImage per capire che forse c'è un'importazione mancanti. Tuttavia, non potevo far nulla. Qt Designer di interni di aiuto non tutto come bene. È come se questo componente non esiste. Ma lo fa, e funziona in Studio di Design.

Ecco il codice completo per il mio pulsante:

Button {
    id: actionBarButton

    property color iconColor: "red"
    property color backgroundColor: "blue"
    property string toolTipText: "Play video!"
    property string imageSource: "images/round_play_arrow_white_36dp.png"
    property string imageSourceChecked: "images/round_play_arrow_white_36dp.png"

    states: [
        State {
            when: (hovered && !checked)
            name: "hoveredNotChecked"
            PropertyChanges {
                target: buttonIcon
                color: "white"
            }

            PropertyChanges {
                target: buttonBackground
                color: iconColor
            }
        },
        State {
            when: (hovered && checked)
            name: "hoveredChecked"
            PropertyChanges {
                target: buttonIcon
                source: imageSourceChecked
                color: "white"
            }

            PropertyChanges {
                target: buttonBackground
                color: iconColor
            }
        },
        State {
            when: checked
            name: "checked"
            PropertyChanges {
                target: buttonIcon
                source: imageSourceChecked
            }
        }
    ]

    transitions: Transition {

        ColorAnimation {
            duration: 300
        }
    }

    contentItem: ColorImage {
        id: buttonIcon
        source: imageSource
        fillMode: Image.PreserveAspectFit
        height: parent.height
        color: iconColor
        anchors.fill: actionBarButton
        anchors.margins: 4
    }

    onHoveredChanged: {

    }
    background: Rectangle {
        id: buttonBackground
        color: backgroundColor
        anchors.fill: actionBarButton
    }

    ToolTip.delay: 1000
    ToolTip.timeout: 5000
    ToolTip.visible: hovered
    ToolTip.text: actionBarButton.toolTipText
}

Questo è come appare nella finestra di progettazione: Here is how it looks in the designer

Qualcuno mi può aiutare a capire perché si lamenta ColorImagenon essendo un tipo quando provo a lanciare?

Edit:

Le importazioni nel file di cui sopra:

import QtQuick 2.15
import QtQuick.Controls 2.15
pyside2 qml qt
2021-11-14 14:36:50
1

Migliore risposta

2

ColorImage è un Qt privato interno del componente:

https://github.com/qt/qtdeclarative/blob/dev/src/quickcontrols2impl/qquickcolorimage.cpp

Non sembra essere supportata per il non-uso interno.

Se si desidera utilizzarlo, provare import QtQuick.Controls.impl 2.15

Nota che ColorOverlay è di nuovo disponibile, Qt 6.2 in Qt5Compat:

https://doc.qt.io/qt-6/qml-qt5compat-graphicaleffects-coloroverlay.html

Alla fine sarà sostituito da Qt Quick Processore:

https://marketplace.qt.io/products/qt-quick-multieffect

2021-11-14 16:05:34

Grazie questo mi ha aiutato a risolvere il mio problema!
Curtwagner1984

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................