Qt, QML, ColorImage bir tür değil

0

Soru

Bir QML düğmesi bileşeni yaptım ve adında bir bileşen kullandım ColorImage simge için. Görüntü rengini değiştirmenin bir yolunu aradıktan sonra. Qt'nin artık coloroverlay'i desteklemediğini öğrendim

Hover, Qt Design Studio'da 'renk' yazdım ve ColorImage attı. İnternette dokümantasyon bulmaya çalıştım ama hiçbir şey bulamadım. Ancak, denemeye karar verdiğimde, beklediğim gibi çalışıyor:

Bu benim düğmemdeki ilgili kod:

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

Ne zaman hovered düğmeden durum olur true aşağıdaki durumu etkinleştirir:

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

            PropertyChanges {
                target: buttonBackground
                color: iconColor
            }
        },

düğmedeki simgeyi ve arka plan rengini değiştirir.

Bu, Qt Tasarımcısının önizlemesinde çalışır. Ancak, onu Pyside'dan çalıştırmaya çalıştığımda, bana: ColorImage is not a type ve sadece düğmeyi yüklemek için başarısız olur.

Hakkında belgeler bulmaya çalıştım. ColorImage belki bir ithalatın eksik olduğunu anlamak için. Ancak, hiçbir şey bulamadım. Qt Designer'ın dahili yardımı da hiçbir şey ortaya çıkarmadı. Sanki bu bileşen yokmuş gibi. Ama öyle ve Tasarım Stüdyosunda çalışıyor.

İşte düğmem için tam kod:

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
}

Tasarımcıda böyle görünüyor: Here is how it looks in the designer

Biri şikayet hakkında onu bunu anlamam için bana yardımcı olabilir ColorImagefırlatmaya çalıştığımda tiplik yapmıyor muyum?

Düzenlemek:

Yukarıdaki dosyadaki içe aktarmalar:

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

En iyi cevabı

2

ColorImage bir Qt dahili özel bileşenidir:

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

Dahili olmayan kullanım için desteklenmiyor gibi görünüyor.

Gerçekten kullanmak istiyorsan, dene import QtQuick.Controls.impl 2.15

Coloroverlay'in Qt5Compat uygulamasında Qt 6.2'de tekrar kullanılabileceğini unutmayın:

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

Sonunda Qt Quick MultiEffect ile değiştirilecektir:

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

2021-11-14 16:05:34

Teşekkür ederim bu yardım çözüldü benim sorun!
Curtwagner1984

Diğer dillerde

Bu sayfa diğer dillerde

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