本文整理汇总了Python中PyQt5.QtWidgets.QWidget.pos方法的典型用法代码示例。如果您正苦于以下问题:Python QWidget.pos方法的具体用法?Python QWidget.pos怎么用?Python QWidget.pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QWidget
的用法示例。
在下文中一共展示了QWidget.pos方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _TitleBar
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import pos [as 别名]
class _TitleBar(QToolBar):
"""Widget title bar.
Contains standard dock widget buttons and allows to add new buttons and widgets
"""
def __init__(self, parent, *args):
QToolBar.__init__(self, parent, *args)
self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum))
self._dock = parent
self.aClose = QToolBar.addAction(self, self.style().standardIcon(QStyle.SP_TitleBarCloseButton), "")
closeIcon = self.style().standardIcon(QStyle.SP_DockWidgetCloseButton)
if not closeIcon.availableSizes():
# SP_DockWidgetCloseButton is missing on Fedora. Why??? Using fallback
closeIcon = self.style().standardIcon( QStyle.SP_DialogCloseButton)
self.aClose = QToolBar.addAction(self, closeIcon, "")
self.setMovable(False)
self.setFloatable(False)
self.aClose.triggered.connect(self._dock.close)
textHeight = QFontMetrics(self.font()).height()
self.setIconSize(QSize(textHeight, textHeight))
# a fake spacer widget
self._spacer = QWidget(self)
self._spacer.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.MinimumExpanding))
self.addWidget(self._spacer)
def paintEvent(self, event):
"""QToolBar.paintEvent reimplementation
Draws buttons, dock icon and text
"""
rect = self._spacer.rect()
painter = QPainter(self)
transform = QTransform()
transform.translate(self._spacer.pos().x(), self._spacer.pos().y())
painter.setTransform(transform)
""" Not supported currently
if self._dock.features() & QDockWidget.DockWidgetVerticalTitleBar :
transform = QTransform()
rect.setSize(QSize(rect.height(), rect.width()))
transform.rotate(-90)
transform.translate(-rect.width(), 0)
painter.setTransform(transform)
"""
# icon / title
optionB = QStyleOptionButton()
optionB.initFrom(self._dock)
optionB.rect = rect
optionB.text = self._dock.windowTitle()
optionB.iconSize = self.iconSize()
optionB.icon = self._dock.windowIcon()
self.style().drawControl(QStyle.CE_PushButtonLabel, optionB, painter, self._dock)
def minimumSizeHint(self):
"""QToolBar.minimumSizeHint implementation
"""
return QToolBar.sizeHint(self)
def sizeHint(self):
"""QToolBar.sizeHint implementation
"""
wis = self.iconSize()
size = QToolBar.sizeHint(self)
fm = QFontMetrics(self.font())
if self._dock.features() & QDockWidget.DockWidgetVerticalTitleBar:
size.setHeight(size.height() + fm.width(self._dock.windowTitle()) + wis.width())
else:
size.setWidth(size.width() + fm.width(self._dock.windowTitle()) + wis.width())
return size
def addAction(self, action):
"""QToolBar.addAction implementation
Adjusts indexes for behaving like standard empty QTitleBar
"""
return self.insertAction(self.aClose, action)
def addSeparator(self):
"""QToolBar.addAction implementation
Adjusts indexes for behaving like standard empty QTitleBar
"""
return self.insertSeparator(self.aClose)
def addWidget(self, widget):
"""QToolBar.addAction implementation
Adjusts indexes for behaving like standard empty QTitleBar
"""
#.........这里部分代码省略.........
示例2: print
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import pos [as 别名]
#以屏幕左上角为(0, 0)点
widget.move(250, 200)
widget.setWindowTitle('PyQt坐标系统例子')
widget.show()
print("#1 QWidget")
print("widget.x()=%d" % widget.x() )
print("widget.y()=%d" % widget.y() )
print("widget.width()=%d" % widget.width() )
print("widget.height()=%d" % widget.height() )
print("#2 QWidget.geometry")
print("widget.geometry().x()=%d" % widget.geometry().x() )
print("widget.geometry().y()=%d" % widget.geometry().y() )
print("widget.geometry().width()=%d" % widget.geometry().width() )
print("widget.geometry().height()=%d" % widget.geometry().height() )
print("widget.size().width() =%d" % widget.size().width() )
print("widget.size().height() =%d" % widget.size().height() )
print("#3 QWidget.frameGeometry")
print("widget.frameGeometry().width()=%d" % widget.frameGeometry().width() )
print("widget.frameGeometry().height()=%d" % widget.frameGeometry().height() )
print("widget.pos().x()=%d" % widget.pos().x() )
print("widget.pos().y()=%d" % widget.pos().y() )
sys.exit(app.exec_())
示例3: E5AnimatedWidget
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import pos [as 别名]
class E5AnimatedWidget(QWidget):
"""
Class implementing an animated widget.
"""
DirectionDown = 0
DirectionUp = 1
def __init__(self, direction=DirectionDown, duration=300, parent=None):
"""
Constructor
@param direction direction of the animation
@type int (one of DirectionDown or DirectionUp)
@param duration duration of the animation
@type int
@param parent reference to the parent widget
@type QWidget
"""
super(E5AnimatedWidget, self).__init__(parent)
self.__direction = direction
self.__stepHeight = 0.0
self.__stepY = 0.0
self.__startY = 0
self.__widget = QWidget(self)
self.__timeline = QTimeLine(duration)
self.__timeline.setFrameRange(0, 100)
self.__timeline.frameChanged.connect(self.__animateFrame)
self.setMaximumHeight(0)
def widget(self):
"""
Public method to get a reference to the animated widget.
@return reference to the animated widget
@rtype QWidget
"""
return self.__widget
@pyqtSlot()
def startAnimation(self):
"""
Public slot to start the animation.
"""
if self.__timeline.state() == QTimeLine.Running:
return
shown = 0
hidden = 0
if self.__direction == self.DirectionDown:
shown = 0
hidden = -self.__widget.height()
self.__widget.move(QPoint(self.__widget.pos().x(), hidden))
self.__stepY = (hidden - shown) / 100.0
self.__startY = hidden
self.__stepHeight = self.__widget.height() / 100.0
self.__timeline.setDirection(QTimeLine.Forward)
self.__timeline.start()
@pyqtSlot(int)
def __animateFrame(self, frame):
"""
Private slot to animate the next frame.
@param frame frame number
@type int
"""
self.setFixedHeight(frame * self.__stepHeight)
self.__widget.move(self.pos().x(),
self.__startY - frame * self.__stepY)
@pyqtSlot()
def hide(self):
"""
Public slot to hide the animated widget.
"""
if self.__timeline.state() == QTimeLine.Running:
return
self.__timeline.setDirection(QTimeLine.Backward)
self.__timeline.finished.connect(self.close)
self.__timeline.start()
p = self.parentWidget()
if p is not None:
p.setFocus()
def resizeEvent(self, evt):
"""
Protected method to handle a resize event.
@param evt reference to the event object
@type QResizeEvent
"""
#.........这里部分代码省略.........
示例4: _TitleBar
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import pos [as 别名]
class _TitleBar(QToolBar):
"""Widget title bar.
Contains standard dock widget buttons and allows to add new buttons and widgets
"""
def __init__(self, parent, *args):
QToolBar.__init__(self, parent, *args)
self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum))
self._dock = parent
closeIcon = self.style().standardIcon(QStyle.SP_DockWidgetCloseButton)
if not closeIcon.availableSizes():
# SP_DockWidgetCloseButton is missing on Fedora. Why??? Using fallback
closeIcon = self.style().standardIcon(QStyle.SP_DialogCloseButton)
self.aClose = QToolBar.addAction(self, closeIcon, "")
self.setMovable(False)
self.setFloatable(False)
self.aClose.triggered.connect(self._dock.close)
textHeight = QFontMetrics(self.font()).height()
self.setIconSize(QSize(textHeight * 0.8, textHeight * 0.8))
# a fake spacer widget
self._spacer = QWidget(self)
self._spacer.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.MinimumExpanding))
self.addWidget(self._spacer)
self.setStyleSheet('QToolBar{spacing:0px; margin:0px}')
# The pinned/unpinned control.
self.tbUnPinned = QToolButton()
icon = QIcon()
# To do: Replace with my own image and put in resources.
icon.addPixmap(QPixmap(os.path.join(os.path.dirname(__file__), 'unpinned.png')), QIcon.Normal, QIcon.On)
icon.addPixmap(QPixmap(os.path.join(os.path.dirname(__file__), 'pinned.png')), QIcon.Normal, QIcon.Off)
self.tbUnPinned.setIcon(icon)
self.tbUnPinned.setCheckable(True)
self._configName = parent.windowTitle() + " pinned"
if self._configName in core.config():
self.tbUnPinned.setChecked(not core.config()[self._configName])
self.tbUnPinned.toggled.connect(self.on_tbUnPinned_toggled)
self.addWidget(self.tbUnPinned)
def on_tbUnPinned_toggled(self, checked):
core.config()[self._configName] = not checked
core.config().flush()
def paintEvent(self, event):
"""QToolBar.paintEvent reimplementation
Draws buttons, dock icon and text
"""
rect = self._spacer.rect()
painter = QPainter(self)
transform = QTransform()
transform.translate(self._spacer.pos().x(), self._spacer.pos().y())
painter.setTransform(transform)
""" Not supported currently
if self._dock.features() & QDockWidget.DockWidgetVerticalTitleBar :
transform = QTransform()
rect.setSize(QSize(rect.height(), rect.width()))
transform.rotate(-90)
transform.translate(-rect.width(), 0)
painter.setTransform(transform)
"""
# icon / title
optionB = QStyleOptionButton()
optionB.initFrom(self._dock)
optionB.rect = rect
optionB.text = self._dock.windowTitle()
optionB.iconSize = self.iconSize()
optionB.icon = self._dock.windowIcon()
self.style().drawControl(QStyle.CE_PushButtonLabel, optionB, painter, self._dock)
def minimumSizeHint(self):
"""QToolBar.minimumSizeHint implementation
"""
return QToolBar.sizeHint(self)
def sizeHint(self):
"""QToolBar.sizeHint implementation
"""
wis = self.iconSize()
size = QToolBar.sizeHint(self)
fm = QFontMetrics(self.font())
if self._dock.features() & QDockWidget.DockWidgetVerticalTitleBar:
size.setHeight(size.height() + fm.width(self._dock.windowTitle()) + wis.width())
else:
size.setWidth(size.width() + fm.width(self._dock.windowTitle()) + wis.width())
#.........这里部分代码省略.........