icon.source property not working in QML Button?

Belz Ulrich ulbemu at mnet-online.de
Mon May 2 22:26:15 BST 2022


Hello,

It looks like the icon.source property of a QML Button is not working 
(PyQt 6.2.2). The referenced image is not shown. Example to reproduce:

buttontest.py:
import sys

from PyQt6.QtGui import QGuiApplication
from PyQt6.QtQml import QQmlApplicationEngine

if __name__=="__main__":

   app = QGuiApplication(sys.argv)
   engine = QQmlApplicationEngine()
   engine.quit.connect(app.quit)
   engine.load('buttontest.qml')

   sys.exit(app.exec())


buttontest.qml:
import QtQuick
import QtQuick.Controls 2.15

import QtQuick.Controls.Material 2.15

ApplicationWindow {
   visible: true
   width: 400
   height: 200
   title: "Button Test"
   Material.theme: Material.Dark
   color: "#111111"

   ScreenA {
     id: screenA
   }
}

ScreenA.qml:
import QtQuick import QtQuick.Controls 2.15 import 
QtQuick.Controls.Material 2.15
Rectangle {
   id: rectangle
   width: 400
   height: 200
   color: "#000000"
   border.color: "#000000"

   Image {
     id: btni
source: "./icon-arrow-down-red.png"
   }

   Button {
     id: button
     x: 200
     y: 100
     width: 48
     height: 48
     visible: true
     display: Button.IconOnly
     icon.source: "./icon-arrow-down-red.png"
     icon.color: "transparent"
     text: "Text" }
}

The Image works well, the Button not.


Am I doing something wrong?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220502/98d63198/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: icon-arrow-down-red.png
Type: image/png
Size: 415 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220502/98d63198/attachment.png>


More information about the PyQt mailing list