I have a problem with QToolbar and QAction. I'm trying to show an action with a icon but the icon is not showing.
This is my qrc and code example (I'm using PySide2):
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/iconos">
<file alias="vista-inicial.svg">iconos/cubo.svg</file>
<file alias="cubo.png">iconos/3d.png</file>
</qresource>
</RCC>
import sys
from PySide2 import QtCore, QtWidgets, QtGui
class MyWidget(QtWidgets.QWidget):
def __init__(self):
super().__init__()
toolbar = QtWidgets.QToolBar()
toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
toolbar.setIconSize(QtCore.QSize(24, 24))
accion_vista_inicial = QtWidgets.QAction(QtGui.QIcon(":iconos/cubo.png"), "Vista Inicial", self)
toolbar.addAction(accion_vista_inicial)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(QtWidgets.QLabel("Test"))
self.setLayout(layout)
self.show()
def main():
app = QtWidgets.QApplication(sys.argv)
test = MyWidget()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
And finally a little screenshot:
You need to convert the .qrc into .py and import it into your script: