QPushButton Icon

More
07 Dec 2020 20:36 #191355 by prochj51
QPushButton Icon was created by prochj51
Hi,

I am trying to replace text of QPushButton with .svg icon.
I added it into resource.qrc file as play.svg and changed stylesheet to
QPushButton
{
   qproperty-icon:url(":play.svg")
}

And the icon shows up properly in QtDesigner.
But when I run linuxcnc I get this error:
qt.svg: Cannot open file ':play.svg', because: No such file or directory

Does anyone know how it should be done properly.
I am attaching my files just in case.

Thanks in advance
Jiri

File Attachment:

File Name: craftsman.zip
File Size:22 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
22 Dec 2020 16:04 #192831 by KCJ
Replied by KCJ on topic QPushButton Icon
Hello Jiri,

Sorry for the late reply.
I find it better to use relative paths in the QSS file rather than the recourse paths (paths that begin with ":"). The icon may not show up in designer this way since it will not always be able to resolve a relative path, but it will work when the run the application normally.

The path is relative to the QSS file, so if you have a separate icons dir that is up one level from your QSS file location, you would use a path that looks something like this:
QPushButton
{
   qproperty-icon:url("../icons/play.svg")
}

Cheers,
Kurt

Please Log in or Create an account to join the conversation.

Moderators: KCJLcvette
Time to create page: 0.064 seconds
Powered by Kunena Forum