Nominate our 2022 Qt Champions!

Cannot set an image background in a Button (qt quick controls)

  • In a qt qml quick project, I've this code:

    @import QtQuick 2.1
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0@
    .... ..... ....
    @Button {
    id: button1
    x: 160
    y: 130
    width: 50
    height: 50
    text: ""
    iconSource: "../../img/up.png"

    Compiling, there are no errors or warnings, but the button have no image in background!
    Image for the background is 32x32 Png format.
    Why it does'no work?

  • This should work fine but I believe we have added a bug fix to the base style (i.e not platform specific style in 5.1.1). If you are using QGuiApplication and not QApplication, that would be the most likely reason you are not seeing the icon right now.

    To work around it, you might simply add an Image as a child of the button, or you can override the label component in a ButtonStyle.

  • Thank you, I've work around it with the Image child solution

Log in to reply