Setting svg icon for TabButton
-
I am trying to set an svg icon for a TabButton here is my code:
main.qml:
import QtQuick 2.7 import QtQuick.Controls 2.7 Window { id: window width: 900 height: 600 visible: true title: qsTr("SVG test") TabButton { width: 200 height: 30 anchors.centerIn: parent text: "Click me!" icon.source: "qrc:/icons/feather-dark/svg/activity.svg" } }
I checked my qrc file multiple times and the icon is there:
I also right-click and copy the path from the Qt creator IDE to make sure that the path is correct.
Yet the icon is not shown when ruining. Why is that?
-
@Markkyboy Unfortunately, there is no error or warning.
I tried every possible combination from using absolute path to resource file with qrc from removing extension to using extension and even setting height and width.
The end result is the same:
No icon is showing and there is no messages displayed by the complier/interpreter/IDE in the debug/info messages section
-
It might sound silly if you have no console messages but do you have
QT += svg
Included in your .pro file?
-
@Allstar12345 I am using Cmake so I have this:
find_package(Qt6 REQUIRED COMPONENTS Svg)
target_link_libraries(mytarget PRIVATE Qt6::Svg) -
@Saviz I guess the path of the svg file may not be right. Can you post your qrc file here?
do you use qmake or cmake?TabButton { id: root implicitHeight: *** implicitWidth: *** contentItem: Label { anchors.fill: parent Row { spacing: Image { id: buttonImage height: root.height width: root.height source:svg file } Text { text: root.text height: root.height width: root.availableWidth color: "white" horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter } } } }