简体   繁体   中英

QPushButton not display Button icon

So i have created a window using QtDesigner and i added an icon to the QPushButton in the window (self.wlcm_registerbtn).

but after pyuic5 the file, the icon just don't want to show itself anymore knowing that the image file is in the same directory as the .ui and .py file. so this is the code part of the QpushButton generated from pyuic5 :

Feel free to mark this question as duplicate if you have already helped someone with the same issue. thank you in advance !

self.wlcm_registerbtn = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Segoe UI")
font.setWeight(50)
self.wlcm_registerbtn.setFont(font)
icon_registerbtn = QtGui.QIcon()
icon_registerbtn.addPixmap(QtGui.QPixmap("images/registericon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.wlcm_registerbtn.setIcon(icon_registerbtn)
self.wlcm_registerbtn.setObjectName("wlcm_registerbtn")
self.gridLayout.addWidget(self.wlcm_registerbtn, 1, 1, 1, 1)

Error fixed by stating the full path of .png's. Full Path:

C:/users/pc/desktop/*pydirectory/*pngdirectory/*pngfilename.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM