本文整理汇总了Python中qtpy.QtGui.QPixmap.height方法的典型用法代码示例。如果您正苦于以下问题:Python QPixmap.height方法的具体用法?Python QPixmap.height怎么用?Python QPixmap.height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtGui.QPixmap
的用法示例。
在下文中一共展示了QPixmap.height方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zoom_figure_viewer
# 需要导入模块: from qtpy.QtGui import QPixmap [as 别名]
# 或者: from qtpy.QtGui.QPixmap import height [as 别名]
def test_zoom_figure_viewer(figbrowser, tmpdir, fmt):
"""
Test zooming in and out the figure diplayed in the figure viewer.
"""
fig = add_figures_to_browser(figbrowser, 1, tmpdir, fmt)[0]
figcanvas = figbrowser.figviewer.figcanvas
# Calculate original figure size in pixels.
qpix = QPixmap()
qpix.loadFromData(fig, fmt.upper())
fwidth, fheight = qpix.width(), qpix.height()
assert figbrowser.zoom_disp.value() == 100
assert figcanvas.width() == fwidth
assert figcanvas.height() == fheight
# Zoom in and out the figure in the figure viewer.
scaling_factor = 0
scaling_step = figbrowser.figviewer._scalestep
for zoom_step in [1, 1, -1, -1, -1]:
if zoom_step == 1:
figbrowser.zoom_in()
elif zoom_step == -1:
figbrowser.zoom_out()
scaling_factor += zoom_step
scale = scaling_step**scaling_factor
assert figbrowser.zoom_disp.value() == np.floor(scale * 100)
assert figcanvas.width() == np.floor(fwidth * scale)
assert figcanvas.height() == np.floor(fheight * scale)
示例2: SearchLineEdit
# 需要导入模块: from qtpy.QtGui import QPixmap [as 别名]
# 或者: from qtpy.QtGui.QPixmap import height [as 别名]
class SearchLineEdit(QLineEdit):
"""Line edit search widget with icon and remove all button"""
def __init__(self, parent=None, icon=True):
super(SearchLineEdit, self).__init__(parent)
self.setTextMargins(1, 0, 20, 0)
if icon:
self.setTextMargins(18, 0, 20, 0)
self._label = QLabel(self)
self._pixmap_icon = QPixmap(get_image_path('conda_search.png'))
self._label.setPixmap(self._pixmap_icon)
self._label.setStyleSheet('''border: 0px; padding-bottom: 0px;
padding-left: 2px;''')
self._pixmap = QPixmap(get_image_path('conda_del.png'))
self.button_clear = QToolButton(self)
self.button_clear.setIcon(QIcon(self._pixmap))
self.button_clear.setIconSize(QSize(18, 18))
self.button_clear.setCursor(Qt.ArrowCursor)
self.button_clear.setStyleSheet("""QToolButton
{background: transparent;
padding-right: 2px; border: none; margin:0px; }""")
self.button_clear.setVisible(False)
# Layout
self._layout = QHBoxLayout(self)
self._layout.addWidget(self.button_clear, 0, Qt.AlignRight)
self._layout.setSpacing(0)
self._layout.setContentsMargins(0, 2, 2, 0)
# Signals and slots
self.button_clear.clicked.connect(self.clear_text)
self.textChanged.connect(self._toggle_visibility)
self.textEdited.connect(self._toggle_visibility)
def _toggle_visibility(self):
""" """
if len(self.text()) == 0:
self.button_clear.setVisible(False)
else:
self.button_clear.setVisible(True)
def sizeHint(self):
return QSize(200, self._pixmap_icon.height())
# Public api
# ----------
def clear_text(self):
""" """
self.setText('')
self.setFocus()
示例3: FigureCanvas
# 需要导入模块: from qtpy.QtGui import QPixmap [as 别名]
# 或者: from qtpy.QtGui.QPixmap import height [as 别名]
class FigureCanvas(QFrame):
"""
A basic widget on which can be painted a custom png, jpg, or svg image.
"""
def __init__(self, parent=None, background_color=None):
super(FigureCanvas, self).__init__(parent)
self.setLineWidth(2)
self.setMidLineWidth(1)
self.setObjectName("figcanvas")
self.setStyleSheet(
"#figcanvas {background-color:" + str(background_color) + "}")
self.fig = None
self.fmt = None
self.fwidth, self.fheight = 200, 200
self._blink_flag = False
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.context_menu_requested)
def context_menu_requested(self, event):
"""Popup context menu."""
if self.fig:
pos = QPoint(event.x(), event.y())
context_menu = QMenu(self)
context_menu.addAction(ima.icon('editcopy'), "Copy Image",
self.copy_figure,
QKeySequence(
get_shortcut('plots', 'copy')))
context_menu.popup(self.mapToGlobal(pos))
@Slot()
def copy_figure(self):
"""Copy figure to clipboard."""
if self.fmt in ['image/png', 'image/jpeg']:
qpixmap = QPixmap()
qpixmap.loadFromData(self.fig, self.fmt.upper())
QApplication.clipboard().setImage(qpixmap.toImage())
elif self.fmt == 'image/svg+xml':
svg_to_clipboard(self.fig)
else:
return
self.blink_figure()
def blink_figure(self):
"""Blink figure once."""
if self.fig:
self._blink_flag = not self._blink_flag
self.repaint()
if self._blink_flag:
timer = QTimer()
timer.singleShot(40, self.blink_figure)
def clear_canvas(self):
"""Clear the figure that was painted on the widget."""
self.fig = None
self.fmt = None
self._qpix_buffer = []
self.repaint()
def load_figure(self, fig, fmt):
"""
Load the figure from a png, jpg, or svg image, convert it in
a QPixmap, and force a repaint of the widget.
"""
self.fig = fig
self.fmt = fmt
if fmt in ['image/png', 'image/jpeg']:
self._qpix_orig = QPixmap()
self._qpix_orig.loadFromData(fig, fmt.upper())
elif fmt == 'image/svg+xml':
self._qpix_orig = QPixmap(svg_to_image(fig))
self._qpix_buffer = [self._qpix_orig]
self.fwidth = self._qpix_orig.width()
self.fheight = self._qpix_orig.height()
def paintEvent(self, event):
"""Qt method override to paint a custom image on the Widget."""
super(FigureCanvas, self).paintEvent(event)
# Prepare the rect on which the image is going to be painted :
fw = self.frameWidth()
rect = QRect(0 + fw, 0 + fw,
self.size().width() - 2 * fw,
self.size().height() - 2 * fw)
if self.fig is None or self._blink_flag:
return
# Check/update the qpixmap buffer :
qpix2paint = None
for qpix in self._qpix_buffer:
if qpix.size().width() == rect.width():
qpix2paint = qpix
break
else:
if self.fmt in ['image/png', 'image/jpeg']:
#.........这里部分代码省略.........
示例4: FigureCanvas
# 需要导入模块: from qtpy.QtGui import QPixmap [as 别名]
# 或者: from qtpy.QtGui.QPixmap import height [as 别名]
class FigureCanvas(QFrame):
"""
A basic widget on which can be painted a custom png, jpg, or svg image.
"""
def __init__(self, parent=None):
super(FigureCanvas, self).__init__(parent)
self.setLineWidth(2)
self.setMidLineWidth(1)
self.setStyleSheet("background-color: white")
self.fig = None
self.fmt = None
self.fwidth, self.fheight = 200, 200
def clear_canvas(self):
"""Clear the figure that was painted on the widget."""
self.fig = None
self.fmt = None
self._qpix_buffer = []
self.repaint()
def load_figure(self, fig, fmt):
"""
Load the figure from a png, jpg, or svg image, convert it in
a QPixmap, and force a repaint of the widget.
"""
self.fig = fig
self.fmt = fmt
if fmt in ['image/png', 'image/jpeg']:
self._qpix_orig = QPixmap()
self._qpix_orig.loadFromData(fig, fmt.upper())
elif fmt == 'image/svg+xml':
self._qpix_orig = QPixmap(svg_to_image(fig))
self._qpix_buffer = [self._qpix_orig]
self.fwidth = self._qpix_orig.width()
self.fheight = self._qpix_orig.height()
def paintEvent(self, event):
"""Qt method override to paint a custom image on the Widget."""
super(FigureCanvas, self).paintEvent(event)
# Prepare the rect on which the image is going to be painted :
fw = self.frameWidth()
rect = QRect(0 + fw, 0 + fw,
self.size().width() - 2 * fw,
self.size().height() - 2 * fw)
if self.fig is None:
return
# Check/update the qpixmap buffer :
qpix2paint = None
for qpix in self._qpix_buffer:
if qpix.size().width() == rect.width():
qpix2paint = qpix
break
else:
if self.fmt in ['image/png', 'image/jpeg']:
qpix2paint = self._qpix_orig.scaledToWidth(
rect.width(), mode=Qt.SmoothTransformation)
elif self.fmt == 'image/svg+xml':
qpix2paint = QPixmap(svg_to_image(self.fig, rect.size()))
self._qpix_buffer.append(qpix2paint)
if qpix2paint is not None:
# Paint the image on the widget :
qp = QPainter()
qp.begin(self)
qp.drawPixmap(rect, qpix2paint)
qp.end()