当前位置: 首页>>代码示例>>Python>>正文


Python QWidget.setPixmap方法代码示例

本文整理汇总了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)
开发者ID:rr-,项目名称:dotfiles,代码行数:31,代码来源:widget.py

示例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)
	
#.........这里部分代码省略.........
开发者ID:Nick3869,项目名称:UI,代码行数:103,代码来源:hardiprep_ui.py


注:本文中的PyQt5.QtWidgets.QWidget.setPixmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。