Qt Built in Resources

dila

New member
Finding nice artwork for your UI is a pain, especially if you want a consistent look.

But Qt DLL's have a bunch of icons (also known as "pixmaps" in the Qt world) built in. They are there, so you might as well use them:

Code:
#include <QPushButton>
#include <QStyle>
 
QPushButton* button = new QPushButton(this);
button->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon));

This will create a standard Qt button, but will have a "file open" icon, suitable for use on a browse button for a save dialog, for example.

You can see that the icon is defined as an enum as a member of the QStyle class. A full list of the icons available in Qt 5.0 is here:

http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum

Hope you find this tip useful to improve the look of your own Qt applications.

Regards, dila
 

Storm Shadow

Administrator
Staff member
Developer
Ida Pro Expert
Elite Cracker
I actuelly didnt know Qt had standard icons for various standard stuff.

so same icon, but in PyQt would be

line 31
Python:
from PyQt4 import QtCore, QtGui
 
try:
	_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
	def _fromUtf8(s):
		return s
 
try:
	_encoding = QtGui.QApplication.UnicodeUTF8
	def _translate(context, text, disambig):
		return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
	def _translate(context, text, disambig):
		return QtGui.QApplication.translate(context, text, disambig)
 
class Ui_Form(object):
	def setupUi(self, Form):
		Form.setObjectName(_fromUtf8("Form"))
		Form.resize(400, 300)
		self.pushButton = QtGui.QPushButton(Form)
		self.pushButton.setGeometry(QtCore.QRect(114, 102, 111, 51))
		self.pushButton.setObjectName(_fromUtf8("pushButton"))
 
		self.retranslateUi(Form)
		QtCore.QMetaObject.connectSlotsByName(Form)
 
	def retranslateUi(self, Form):
		Form.setWindowTitle(_translate("Form", "Form", None))
		self.pushButton.setText(_translate("Form", "", None))
		self.pushButton.setIcon(QtGui.qApp.style().standardIcon(QtGui.QStyle.SP_DirOpenIcon))
 
 
if __name__ == "__main__":
	import sys
	app = QtGui.QApplication(sys.argv)
	Form = QtGui.QWidget()
	ui = Ui_Form()
	ui.setupUi(Form)
	Form.show()
	sys.exit(app.exec_())
 
Top