本文整理汇总了Python中PyQt5.QtWidgets.QWidget.setPixmap方法的典型用法代码示例。如果您正苦于以下问题:Python QWidget.setPixmap方法的具体用法?Python QWidget.setPixmap怎么用?Python QWidget.setPixmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QWidget
的用法示例。
在下文中一共展示了QWidget.setPixmap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_icon
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setPixmap [as 别名]
def _set_icon(self, widget: QtWidgets.QWidget, icon_name: str) -> None:
if widget.property("icon_name") == icon_name:
return
widget.setProperty("icon_name", icon_name)
icon_path = ROOT_DIR / "data" / "icons" / (icon_name + ".svg")
target_size = QtCore.QSize(18, 18)
stylesheet = ICON_STYLESHEET.format(foreground=Colors.foreground)
icon_content = icon_path.read_text()
icon_content = re.sub(
"(<svg.*>)",
r"\1<style type='text/css'>" + stylesheet + "</style>",
icon_content,
)
svg_renderer = QtSvg.QSvgRenderer(icon_content.encode("utf-8"))
image = QtGui.QPixmap(target_size * self.app.devicePixelRatio())
painter = QtGui.QPainter()
image.fill(QtCore.Qt.transparent)
painter.begin(image)
svg_renderer.render(painter)
painter.end()
image.setDevicePixelRatio(self.app.devicePixelRatio())
widget.setPixmap(image)
示例2: PrepWindow
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setPixmap [as 别名]
class PrepWindow(QMainWindow):
xmlFile = str()
xmlSaved = False
def __init__(self):
super(PrepWindow, self).__init__()
self.initUI()
def initUI(self):
"""
initializing the variable that shows where we are in the GUI
every cwidget (see below) is associated to a special k value
"""
global k
k = 0
self.createXML()
""" the container widget that will contain the cwidget, and the navigation buttons """
self.widget = QWidget()
""" cwidget is the widget that will load the different tabs successively """
self.cwidget = QLabel() # we initialize it with an image
pix = QPixmap("logo.png")
self.cwidget.setPixmap(pix)
""" the statusbar that shows the tooltips associated to all the other components of the window """
self.statusbar = self.statusBar()
""" the next button that will load the new cwidget """
self.next = QPushButton("Create your own Protocol")
self.next.setStatusTip('Proceed to next step')
self.next.clicked.connect(self.nextf)
""" same as next button but to go back one step """
self.back = QPushButton("Load existing Protocol")
self.back.setStatusTip('Go back to previous step')
self.back.clicked.connect(self.backf)
""" taking care of the Layout """
hbox = QHBoxLayout()
hbox.addWidget(self.back)
hbox.addStretch(1)
hbox.addWidget(self.next)
self.wgrid = QGridLayout()
self.wgrid.addWidget(self.cwidget, 0, 0)
self.wgrid.addLayout(hbox, 1, 0)
self.widget.setLayout(self.wgrid)
self.setCentralWidget(self.widget)
self.setWindowTitle('HARDIPrep')
self.show()
"""
to make it possible to quit by using "escape"
"""
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.close()
"""
The fonction that loads the next cwidget
see the doc for further explanations
"""
def nextf(self):
global k
k += 1
print(k)
if k>0:
self.next.setText("Next")
self.back.setText("Back")
if k>1:
self.cwidget.updateXML(self)
self.xmlSaved = False
if not k:
self.next.setText("Create your own Protocol")
self.back.setText("Load existing Protocol")
self.back.clicked.connect(self.backf)
self.back.clicked.disconnect(self.nextf)
self.next.clicked.disconnect(self.runLoaded)
self.next.clicked.connect(self.nextf)
elif k==3:
self.next.setText("Run")
self.next.clicked.connect(self.runCreated)
self.next.clicked.disconnect(self.nextf)
self.changeWidget(k)
#.........这里部分代码省略.........