简体   繁体   English

QPushButton图标未出现

[英]QPushButton icon not appearing

I created a button like this: 我创建了一个像这样的按钮:

icontest = QtGui.QIcon('test.gif');
self.TestButton = QtGui.QPushButton("Test")
self.TestButton.setEnabled(False)
self.TestButton.setIcon(icontest)
self.TestButton.setIconSize(QtCore.QSize(25, 25))
self.TestButton.clicked.connect(goToTestHandler)
self.layout.addWidget(self.TestButton, 0, 1)
... some loading ...
self.TestButton.setEnabled(True)

the button appears, but without the icon - no exception thrown 该按钮出现,但没有图标-不会引发异常

I can reproduce that behavior only when the path passed to the QIcon constructor is wrong. 仅当传递给QIcon构造函数的路径错误时,我才能重现该行为。 Otherwise the icon is displayed. 否则,显示图标。

I have created a button with image in a table cell and the image is appering and working . 我已经在表格单元格中创建了一个带有图像的按钮,并且该图像正在运行。 here is the code. 这是代码。

    newitem = QPushButton(self)
    newitem.setFlat(True)
    newitem.setAutoFillBackground(True)

    palette = newitem.palette();
    palette.setColor(QPalette.Button,QColor(255,255,255));
    newitem.setPalette(palette);
    newitem.setIcon(QIcon("__32__Setting-icon.png"));
    newitem.setIconSize(QSize(22,22));
    self.job_table.setCellWidget(self.table_job_rowCount,6,newitem )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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