本文整理汇总了Python中PyQt5.QtWidgets.QScrollArea.setFocusProxy方法的典型用法代码示例。如果您正苦于以下问题:Python QScrollArea.setFocusProxy方法的具体用法?Python QScrollArea.setFocusProxy怎么用?Python QScrollArea.setFocusProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QScrollArea
的用法示例。
在下文中一共展示了QScrollArea.setFocusProxy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImageDisplay
# 需要导入模块: from PyQt5.QtWidgets import QScrollArea [as 别名]
# 或者: from PyQt5.QtWidgets.QScrollArea import setFocusProxy [as 别名]
#.........这里部分代码省略.........
# and that completes zoom-to-height
# Build the widgetary contents. The widget consists mostly of a vertical
# layout with two items: A scrollArea containing a QLabel used to display
# an image, and a horizontal layout containing the zoom controls.
# TODO: figure out design and location of two cursor-link tool buttons.
def _uic(self):
# Function to return the actual width of the label text
# of a widget. Get the fontMetrics and ask it for the width.
def _label_width(widget):
fm = widget.fontMetrics()
return fm.width(widget.text())
# Create a gray field to use when no image is available
self.gray_image = QPixmap(700,900)
self.gray_image.fill(QColor("gray"))
# Build the QLabel that displays the image pixmap. It gets all
# available space and scales its contents to fit that space.
self.image_display = QLabel()
self.image_display.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
self.image_display.setScaledContents(True)
# Create a scroll area within which to display the image. It will
# create a horizontal and/or vertical scroll bar when
# the image_display size exceeds the size of the scroll area.
self.scroll_area = QScrollArea()
self.scroll_area.setBackgroundRole(QPalette.Dark)
self.scroll_area.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.scroll_area.setWidget(self.image_display)
# Make sure the scroll area does not swallow user keystrokes
self.setFocusPolicy(Qt.ClickFocus) # focus into whole widget
self.scroll_area.setFocusProxy(self) # you, pass it on.
# Create the image-linking toolbuttons.
# Cursor-to-image uses left-hands.
c2i_on = QPixmap(':/hand-left-closed.png')
c2i_off = QPixmap(':/hand-left-open.png')
c2i_con = QIcon()
c2i_con.addPixmap(c2i_on,QIcon.Normal,QIcon.On)
c2i_con.addPixmap(c2i_off,QIcon.Normal,QIcon.Off)
self.cursor_to_image = QToolButton()
self.cursor_to_image.setCheckable(True)
self.cursor_to_image.setContentsMargins(0,0,0,0)
self.cursor_to_image.setIconSize(QSize(30,24))
self.cursor_to_image.setMaximumSize(QSize(32,26))
self.cursor_to_image.setIcon(c2i_con)
# Image-to-cursor uses right-hands.
i2c_on = QPixmap(':/hand-right-closed.png')
i2c_off = QPixmap(':/hand-right-open.png')
i2c_con = QIcon()
i2c_con.addPixmap(i2c_on,QIcon.Normal,QIcon.On)
i2c_con.addPixmap(i2c_off,QIcon.Normal,QIcon.Off)
self.image_to_cursor = QToolButton()
self.image_to_cursor.setCheckable(True)
self.image_to_cursor.setContentsMargins(0,0,0,0)
self.image_to_cursor.setIconSize(QSize(30,24))
self.image_to_cursor.setMaximumSize(QSize(32,26))
self.image_to_cursor.setIcon(i2c_con)
# Create a spinbox to set the zoom from 15 to 200 and connect its
# signal to our slot.
self.zoom_pct = QSpinBox()
self.zoom_pct.setRange(
int(100*ZOOM_FACTOR_MIN),int(100*ZOOM_FACTOR_MAX))