本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.paintEvent方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.paintEvent方法的具體用法?Python QLineEdit.paintEvent怎麽用?Python QLineEdit.paintEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.paintEvent方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: paintEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import paintEvent [as 別名]
def paintEvent(self, event):
"""QLineEdit.paintEvent implementation.
Draws prompt
"""
QLineEdit.paintEvent(self, event)
if self._promptText and not self.text() and self.isEnabled():
option = QStyleOptionFrameV3()
self.initStyleOption(option)
left, top, right, bottom = self.getTextMargins()
va = self.style().visualAlignment(self.layoutDirection(), self.alignment())
rect = (
self.style()
.subElementRect(QStyle.SE_LineEditContents, option, self)
.adjusted(2, 0, 0, 0)
.adjusted(left, top, -right, -bottom)
)
fm = QFontMetrics(self.font())
text = fm.elidedText(self._promptText, Qt.ElideRight, rect.width())
painter = QPainter(self)
painter.setPen(self.palette().color(QPalette.Disabled, QPalette.Text))
painter.drawText(rect, va, text)
示例2: paintEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import paintEvent [as 別名]
def paintEvent(self, event):
QLineEdit.paintEvent(self, event)
if self.base_unit:
panel = QStyleOptionFrame()
self.initStyleOption(panel)
textRect = self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
textRect.adjust(2, 0, -10, 0)
painter = QPainter(self)
painter.setPen(self.help_palette.brush(QPalette.Disabled, QPalette.Text).color())
painter.drawText(textRect, Qt.AlignRight | Qt.AlignVCenter, self.base_unit())
示例3: paintEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import paintEvent [as 別名]
def paintEvent(self, event):
QLineEdit.paintEvent(self, event)
if not self.hasFocus() and not self.text() and self.inactiveText:
options = QStyleOptionFrame()
self.initStyleOption(options)
text_rect = self.style().subElementRect(QStyle.SE_LineEditContents, options, self)
text_rect.adjust(self.left_margin+2, 0, -self.right_margin, 0)
painter = QPainter(self)
painter.setPen(self.palette().brush(QPalette.Disabled, QPalette.Text).color())
painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter, self.inactiveText)
示例4: paintEvent
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import paintEvent [as 別名]
def paintEvent(self, event):
QLineEdit.paintEvent(self, event)
if not bool(self.text()) and self.inactiveText and not self.hasFocus():
panel = QStyleOptionFrame()
self.initStyleOption(panel)
textRect = self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
leftMargin = 2
rightMargin = self._clearButton.iconSize().width()
textRect.adjust(leftMargin, 0, -rightMargin, 0)
painter = QPainter(self)
disabledColor = self.palette().brush(QPalette.Disabled, QPalette.Text).color()
painter.setPen(disabledColor)
painter.drawText(textRect, Qt.AlignLeft|Qt.AlignVCenter, self.inactiveText)