def __init__(self, parent=None):
super(DragWidget, self).__init__(parent)
self.setMinimumSize(200, 200)
self.setFrameStyle(QFrame.Sunken | QFrame.StyledPanel)
self.setAcceptDrops(True)
boatIcon = QLabel(self)
boatIcon.setPixmap(QPixmap(':/images/boat.png'))
boatIcon.move(20, 20)
boatIcon.show()
boatIcon.setAttribute(Qt.WA_DeleteOnClose)
carIcon = QLabel(self)
carIcon.setPixmap(QPixmap(':/images/car.png'))
carIcon.move(120, 20)
carIcon.show()
carIcon.setAttribute(Qt.WA_DeleteOnClose)
houseIcon = QLabel(self)
houseIcon.setPixmap(QPixmap(':/images/house.png'))
houseIcon.move(20, 120)
houseIcon.show()
houseIcon.setAttribute(Qt.WA_DeleteOnClose)
python类QPixmap()的实例源码
def dropEvent(self, event):
if event.mimeData().hasFormat('application/x-dnditemdata'):
itemData = event.mimeData().data('application/x-dnditemdata')
dataStream = QDataStream(itemData, QIODevice.ReadOnly)
pixmap = QPixmap()
offset = QPoint()
dataStream >> pixmap >> offset
newIcon = QLabel(self)
newIcon.setPixmap(pixmap)
newIcon.move(event.pos() - offset)
newIcon.show()
newIcon.setAttribute(Qt.WA_DeleteOnClose)
if event.source() == self:
event.setDropAction(Qt.MoveAction)
event.accept()
else:
event.acceptProposedAction()
else:
event.ignore()
def __init__(self):
super(StickMan, self).__init__()
self.m_sticks = True
self.m_isDead = False
self.m_pixmap = QPixmap('images/head.png')
self.m_penColor = QColor(Qt.white)
self.m_fillColor = QColor(Qt.black)
# Set up start position of limbs.
self.m_nodes = []
for x, y in Coords:
node = Node(QPointF(x, y), self)
node.positionChanged.connect(self.childPositionChanged)
self.m_nodes.append(node)
self.m_perfectBoneLengths = []
for n1, n2 in Bones:
node1 = self.m_nodes[n1]
node2 = self.m_nodes[n2]
dist = node1.pos() - node2.pos()
self.m_perfectBoneLengths.append(math.hypot(dist.x(), dist.y()))
self.startTimer(10)
def updateColor(self, item):
pixmap = QPixmap(16, 16)
color = QColor()
if item:
color = item.backgroundColor()
if not color.isValid():
color = self.palette().base().color()
painter = QPainter(pixmap)
painter.fillRect(0, 0, 16, 16, color)
lighter = color.lighter()
painter.setPen(lighter)
# light frame
painter.drawPolyline(QPoint(0, 15), QPoint(0, 0), QPoint(15, 0))
painter.setPen(color.darker())
# dark frame
painter.drawPolyline(QPoint(1, 15), QPoint(15, 15), QPoint(15, 1))
painter.end()
self.colorAction.setIcon(QIcon(pixmap))
def __init__(self, parent=None):
super(IntroPage, self).__init__(parent)
self.setTitle("Introduction")
self.setPixmap(QWizard.WatermarkPixmap,
QPixmap(':/images/watermark1.png'))
label = QLabel("This wizard will generate a skeleton C++ class "
"definition, including a few functions. You simply need to "
"specify the class name and set a few options to produce a "
"header file and an implementation file for your new C++ "
"class.")
label.setWordWrap(True)
layout = QVBoxLayout()
layout.addWidget(label)
self.setLayout(layout)
def showNextPiece(self):
if self.nextPieceLabel is None:
return
dx = self.nextPiece.maxX() - self.nextPiece.minX() + 1
dy = self.nextPiece.maxY() - self.nextPiece.minY() + 1
pixmap = QPixmap(dx * self.squareWidth(), dy * self.squareHeight())
painter = QPainter(pixmap)
painter.fillRect(pixmap.rect(), self.nextPieceLabel.palette().window())
for i in range(4):
x = self.nextPiece.x(i) - self.nextPiece.minX()
y = self.nextPiece.y(i) - self.nextPiece.minY()
self.drawSquare(painter, x * self.squareWidth(),
y * self.squareHeight(), self.nextPiece.shape())
painter.end()
self.nextPieceLabel.setPixmap(pixmap)
def __init__(self, background='images/world_map.jpg'):
super().__init__(QGraphicsScene())
self.background = QGraphicsPixmapItem(QPixmap(background))
self.addItem(self.background)
self.satellites = []
self.groundStations = []
def reset_data(self):
"""Reset fan rpm and voltage to "---" and activate the red status icon.
Reset CPU and GPU temperature to "0"."""
# Reset fan rpm
self.ui.labelRPMFan1.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan2.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan3.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan4.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan5.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan6.setText('<b><font color="red">---</font></b>')
# Reset fan voltage
self.ui.labelVFan1.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan2.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan3.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan4.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan5.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan6.setText('<b><font color="red">---</font></b>')
# Activate the red led icon
self.ui.labelStatusFan1.setPixmap(QtGui.QPixmap(ICON_RED_LED))
self.ui.labelStatusFan2.setPixmap(QtGui.QPixmap(ICON_RED_LED))
self.ui.labelStatusFan3.setPixmap(QtGui.QPixmap(ICON_RED_LED))
self.ui.labelStatusFan4.setPixmap(QtGui.QPixmap(ICON_RED_LED))
self.ui.labelStatusFan5.setPixmap(QtGui.QPixmap(ICON_RED_LED))
self.ui.labelStatusFan6.setPixmap(QtGui.QPixmap(ICON_RED_LED))
# Reset temperatures
self.ui.lcdNumberCurrentCPU.display(0)
self.ui.lcdNumberCurrentGPU.display(0)
# Update status in UI
self.ui.labelPollingStatus.setText('<b><font color="red">Stopped</font></b>')
self.ui.labelHWMonStatus.setText('<b><font color="red">---</font></b>')
def change_fan_icon(self, icon, fan):
"""Update the fan status icon."""
if fan == 1:
self.ui.labelStatusFan1.setPixmap(QtGui.QPixmap(icon))
if fan == 2:
self.ui.labelStatusFan2.setPixmap(QtGui.QPixmap(icon))
if fan == 3:
self.ui.labelStatusFan3.setPixmap(QtGui.QPixmap(icon))
if fan == 4:
self.ui.labelStatusFan4.setPixmap(QtGui.QPixmap(icon))
if fan == 5:
self.ui.labelStatusFan5.setPixmap(QtGui.QPixmap(icon))
if fan == 6:
self.ui.labelStatusFan6.setPixmap(QtGui.QPixmap(icon))
def __init__(self):
import icons
icon = QIcon(QPixmap(':icon.png'))
super().__init__(icon)
menu = QMenu()
menu.addAction("About").triggered.connect(self.about)
menu.addAction("Exit").triggered.connect(self.exit)
self.setContextMenu(menu)
def __init__(self):
from rockthetaskbar import icons
icon = QIcon(QPixmap(':icon.png'))
super().__init__(icon)
menu = QMenu()
menu.addAction("CPU").triggered.connect(self.cpu)
menu.addAction("About").triggered.connect(self.about)
menu.addAction("Exit").triggered.connect(self.exit)
self.setContextMenu(menu)
self.cpu_monitor = CPUMonitor()
self.cpu_monitor.start()
def init_form(self) -> QHBoxLayout:
self.search_field = QLineEdit(self, clearButtonEnabled=True, placeholderText='Enter search criteria')
self.search_field.setObjectName('searchInput')
self.search_field.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.search_field.setFocus()
self.search_field.textChanged.connect(self.clear_filters)
self.search_field.returnPressed.connect(lambda: self.filter_table(self.search_field.text()))
self.favorites_button = QPushButton(parent=self, flat=True, cursor=Qt.PointingHandCursor,
objectName='favesButton', toolTip='Favorites', checkable=True,
toggled=self.filter_faves,
checked=self.settings.value('faves_filter', False, bool))
self.refresh_button = QPushButton(parent=self, flat=True, cursor=Qt.PointingHandCursor,
objectName='refreshButton', toolTip='Refresh', clicked=self.start_scraping)
self.dlpages_field = QComboBox(self, toolTip='Pages', editable=False, cursor=Qt.PointingHandCursor)
self.dlpages_field.addItems(('10', '20', '30', '40', '50'))
self.dlpages_field.setCurrentIndex(self.dlpages_field.findText(str(self.dl_pagecount), Qt.MatchFixedString))
self.dlpages_field.currentIndexChanged.connect(self.update_pagecount)
self.settings_button = QPushButton(parent=self, flat=True, toolTip='Menu',
objectName='menuButton', cursor=Qt.PointingHandCursor)
self.settings_button.setMenu(self.settings_menu())
layout = QHBoxLayout(spacing=10)
logo = QLabel(self)
logo.setPixmap(QPixmap(':assets/images/logo.png'))
layout.addWidget(logo)
layout.addWidget(self.search_field)
layout.addWidget(self.favorites_button)
layout.addWidget(self.refresh_button)
layout.addWidget(QLabel('Pages:'))
layout.addWidget(self.dlpages_field)
layout.addWidget(self.settings_button)
return layout
def _init_notification_icons(self):
for icon in self.NotifyIcon:
icon_file = QPixmap(icon.value, 'PNG')
icon_file.save(os.path.join(FixedSettings.config_path, os.path.basename(icon.value)), 'PNG', 100)
def __init__(self, parent=None):
super().__init__(parent)
self.setSubTitle(self.tr("<h2>Welcome to KaOS</h2>"))
vlayout = QVBoxLayout(self)
vlayout.addItem(QSpacerItem(20, 30, QSizePolicy.Preferred, QSizePolicy.Minimum))
hlayout = QHBoxLayout(self)
label = QLabel(self)
label.setText(self.tr("""<h1>What is KaOS?</h1>
<p>The idea behind KaOS is to create a tightly integrated rolling and<br />
transparent distribution for the modern desktop, build from scratch with<br />
a very specific focus. Focus on one DE (KDE), one toolkit (Qt) & one architecture (x86_64).<br />
Plus a focus on evaluating and selecting the most suitable tools and applications.</p>
<p>This wizard will help you personalize your KaOS workspace easily and quickly.</p>
<p>Please click <code style=color:#3498DB>Next</code> in order to begin. Click <code style=color:#3498DB>Cancel</code> anytime and changes won't be saved.</p>"""))
label.setWordWrap(True)
label.setAlignment(Qt.AlignLeft)
hlayout.addWidget(label)
kaptan_logo = QLabel(self)
kaptan_logo.setPixmap(QPixmap(":/data/images/welcome.png"))
kaptan_logo.setAlignment(Qt.AlignRight)
kaptan_logo.setMaximumSize(157, 181)
hlayout.addWidget(kaptan_logo)
vlayout.addLayout(hlayout)
vlayout.addItem(QSpacerItem(20, 40, QSizePolicy.Preferred, QSizePolicy.Preferred))
desktop_file = os.path.join(os.environ["HOME"], ".config", "autostart", "kaptan.desktop")
if os.path.exists(desktop_file):
self.checkBox = QCheckBox()
self.checkBox.setText(self.tr("Run on system startup"))
self.checkBox.setChecked(True)
self.checkBox.clicked.connect(self.autoRemove)
vlayout.addWidget(self.checkBox)
def __init__(self, path, version, parent=None):
super(AboutDialog, self).__init__(parent)
self.setupUi(self)
self.label.setPixmap(QtGui.QPixmap(path))
self.label_3.setText('Version %s' % version)
def drawUI(self):
self.play = QPushButton(self)
self.play.setIconSize(QSize(40, 40))
self.play.setIcon(QIcon(QPixmap("play.png").scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation)))
self.play.setStyleSheet("background-color: rgba(0, 0, 0, 0);")
self.play.clicked.connect(lambda:self.playpause(self.play))
self.resize(50, 50)
def playpause(self, btn):
if self.playing:
os.system("""osascript -e 'tell application "iTunes" to pause'""")
self.playing = False
btn.setIcon(QIcon(QPixmap("play.png").scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation)))
else:
os.system("""osascript -e 'tell application "iTunes" to play'""")
self.playing = True
btn.setIcon(QIcon(QPixmap("pause.png").scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation)))
def drawUI(self):
self.play = QPushButton(self)
self.play.setIconSize(QSize(40, 20))
self.play.setIcon(QIcon(QPixmap("fastforward.png").scaled(40, 20, Qt.KeepAspectRatio, Qt.SmoothTransformation)))
self.play.setStyleSheet("background-color: rgba(0, 0, 0, 0);")
self.play.clicked.connect(lambda:self.forward())
self.resize(80, 40)