Solved How to add icon to button?
-
hi guys..
does anybody know how can I insert icon file on Button?
language: QML -
Hi @Taz742
I think that this can be achieved using iconSource property
http://doc.qt.io/qt-5/qml-qtquick-controls-button.html#iconSource-prop
Hope this can help !
-
@mostefa
can you give me some example please :) -
here is a full sample for you,
import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Window 2.2 import QtQuick.Dialogs 1.2 ApplicationWindow { title: qsTr("Hello World") width: 640 height: 480 visible: true Button{ anchors.fill: parent text: "ButtonWithIcon" iconSource: "qrc:/youricon.png" } }
Correct import file according to your Qt versions,
I advise you to read Button doc.
http://doc.qt.io/qt-5/qml-qtquick-controls-button.html -
@mostefa
it works
thanks bro ;) -
You are welcome =)
-
@Taz742 Next time, please give your thread a meaningful title. And when your problem is solved, mark the thread accordingly. We have a small visual forum guide for newcomers: Hitchhiker's Visual Guide to the Qt Forum and there is also the Forum general guide. One more thing: The image upload feature on our forum is broken, see How to insert image on this forum for a workaround. :-)
-
May I extend the question: how do I do that using system theme icons rather then resources?
I've successfully implemented an QQuickImageProvider using QIcon::fromTheme() to access system icons and convert it to pixmap. I've registered it with the engine as "sysicons" and it works flawlessly on Images:
Image { source: "image://sysicons/" + icon }
However, setting iconSource on a button the same way seems to have no effect.
-
@EvilMav You can simply set
iconName
to the the name the icon has in the theme and useiconSource
as a fallback.