本文整理汇总了Python中qtpy.QtWidgets.QWidget方法的典型用法代码示例。如果您正苦于以下问题:Python QtWidgets.QWidget方法的具体用法?Python QtWidgets.QWidget怎么用?Python QtWidgets.QWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets
的用法示例。
在下文中一共展示了QtWidgets.QWidget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def __init__(self, layout: QtWidgets.QLayout, text: str, min: float = None, use_float: bool = True):
""" A spin box with a label next to it.
Args:
layout: the layout to which to add the widget
text: the label text
min: the minimum value of the spin box
use_float: whether to use a float spin box or an int spin box.
"""
QtWidgets.QWidget.__init__(self)
layout.addWidget(self)
self.layout = QtWidgets.QHBoxLayout(self)
self.label = QtWidgets.QLabel(text)
self.layout.addWidget(self.label)
self.layout.setContentsMargins(0, 0, 0, 0)
self.type = float if use_float else int
if use_float is False:
self.input1 = QtWidgets.QSpinBox()
else:
self.input1 = QtWidgets.QDoubleSpinBox()
if min is not None:
self.input1.setMinimum(min)
self.input1.valueChanged.connect(self.valueChangeEvent)
self.layout.addWidget(self.input1)
示例2: _resize_slice_labels
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def _resize_slice_labels(self):
"""When the size of any dimension changes, we want to resize all of the
slice labels to width of the longest label, to keep all the sliders
right aligned. The width is determined by the number of digits in the
largest dimensions, plus a little padding.
"""
width = 0
for ax, maxi in enumerate(self.dims.max_indices):
if self._displayed_sliders[ax]:
length = len(str(int(maxi)))
if length > width:
width = length
# gui width of a string of length `width`
fm = QFontMetrics(QFont("", 0))
width = fm.boundingRect("8" * width).width()
for labl in self.findChildren(QWidget, 'slice_label'):
labl.setFixedWidth(width + 6)
示例3: find_viewer_ancestor
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def find_viewer_ancestor(widget: QWidget) -> Optional[Viewer]:
"""Return the Viewer object if it is an ancestory of ``widget``, else None.
Parameters
----------
widget : QWidget
A widget
Returns
-------
viewer : napari.Viewer or None
Viewer instance if one exists, else None.
"""
parent = widget.parent()
while parent:
if hasattr(parent, 'qt_viewer'):
return parent.qt_viewer.viewer
parent = parent.parent()
return None
示例4: __init__
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def __init__(self, parent: QWidget):
"""About description strings."""
super(PyslvsAbout, self).__init__(parent)
self.setupUi(self)
self.setWindowFlags(self.windowFlags()
& ~Qt.WindowContextHelpButtonHint)
self.title_label.setText(html(_title("Pyslvs") + _content(
f"Version {__version__} 2016-2020"
)))
self.description_text.setText(html(_content(
"A GUI-based tool use to solving 2D linkage subject.",
f"Author: {__author__}",
f"Email: {__email__}",
"If you want to know more, see to our website or contact the email.",
)))
self.license_text.setText(LICENSE_STRING)
self.ver_text.setText(html(_order_list(*SYS_INFO)))
self.args_text.setText(html(_content("Startup arguments are as follows:") + _order_list(
f"Open with: {ARGUMENTS.filepath}",
f"Start Path: {ARGUMENTS.c}",
f"Fusion style: {ARGUMENTS.fusion}",
f"Debug mode: {ARGUMENTS.debug_mode}",
f"Specified kernel: {ARGUMENTS.kernel}",
) + _content("Use \"-h\" or \"--help\" argument to view the help.")))
示例5: __init__
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def __init__(self, parent: QWidget):
super(QRotatableView, self).__init__(parent)
scene = QGraphicsScene(self)
self.setScene(scene)
self.dial = QDial()
self.dial.setMinimumSize(QSize(150, 150))
self.dial.setSingleStep(100)
self.dial.setPageStep(100)
self.dial.setInvertedAppearance(True)
self.dial.setWrapping(True)
self.dial.setNotchTarget(0.1)
self.dial.setNotchesVisible(True)
self.dial.valueChanged.connect(self.__value_changed)
self.set_maximum(360)
graphics_item = scene.addWidget(self.dial)
graphics_item.setRotation(-90)
# make the QGraphicsView invisible.
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setFixedHeight(self.dial.height())
self.setFixedWidth(self.dial.width())
self.setStyleSheet("border: 0px;")
示例6: assert_pyside
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def assert_pyside():
"""
Make sure that we are using PySide
"""
import PySide
assert QtCore.QEvent is PySide.QtCore.QEvent
assert QtGui.QPainter is PySide.QtGui.QPainter
assert QtWidgets.QWidget is PySide.QtGui.QWidget
assert QtWebEngineWidgets.QWebEnginePage is PySide.QtWebKit.QWebPage
示例7: assert_pyside2
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def assert_pyside2():
"""
Make sure that we are using PySide
"""
import PySide2
assert QtCore.QEvent is PySide2.QtCore.QEvent
assert QtGui.QPainter is PySide2.QtGui.QPainter
assert QtWidgets.QWidget is PySide2.QtWidgets.QWidget
assert QtWebEngineWidgets.QWebEnginePage is PySide2.QtWebEngineWidgets.QWebEnginePage
示例8: assert_pyqt4
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def assert_pyqt4():
"""
Make sure that we are using PyQt4
"""
import PyQt4
assert QtCore.QEvent is PyQt4.QtCore.QEvent
assert QtGui.QPainter is PyQt4.QtGui.QPainter
assert QtWidgets.QWidget is PyQt4.QtGui.QWidget
assert QtWebEngineWidgets.QWebEnginePage is PyQt4.QtWebKit.QWebPage
示例9: assert_pyqt5
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def assert_pyqt5():
"""
Make sure that we are using PyQt5
"""
import PyQt5
assert QtCore.QEvent is PyQt5.QtCore.QEvent
assert QtGui.QPainter is PyQt5.QtGui.QPainter
assert QtWidgets.QWidget is PyQt5.QtWidgets.QWidget
if QtWebEngineWidgets.WEBENGINE:
assert QtWebEngineWidgets.QWebEnginePage is PyQt5.QtWebEngineWidgets.QWebEnginePage
else:
assert QtWebEngineWidgets.QWebEnginePage is PyQt5.QtWebKitWidgets.QWebPage
示例10: __init__
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
# 定时器(for 鼠标双击)
self.timer = QtCore.QTimer()
self.timer.setInterval(300)
self.timer.setSingleShot(True)
self.timer.timeout.connect(self.timeout)
self.click_count = 0 # 鼠标点击次数
self.pos = None # 鼠标点击的位置
# 激活鼠标跟踪功能
self.setMouseTracking(True)
示例11: __init__
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def __init__(self, axis: str, signal_target_changed: QtCore.Signal):
""" A widget to change the tick properties
Args:
axis: whether to use the "x" or "y" axis
signal_target_changed: a signal to emit when the target changed
"""
QtWidgets.QWidget.__init__(self)
self.setWindowTitle("Figure - " + axis + "-Axis - Ticks - Pylustrator")
self.setWindowIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__), "icons", "ticks.ico")))
self.layout = QtWidgets.QVBoxLayout(self)
self.axis = axis
self.label = QtWidgets.QLabel(
"Ticks can be specified, one tick pre line.\nOptionally a label can be provided, e.g. 1 \"First\",")
self.layout.addWidget(self.label)
self.layout2 = QtWidgets.QHBoxLayout()
self.layout.addLayout(self.layout2)
self.input_ticks = TextWidget(self.layout2, axis + "-Ticks:", multiline=True, horizontal=False)
self.input_ticks.editingFinished.connect(self.ticksChanged)
self.input_ticks2 = TextWidget(self.layout2, axis + "-Ticks (minor):", multiline=True, horizontal=False)
self.input_ticks2.editingFinished.connect(self.ticksChanged2)
self.input_scale = ComboWidget(self.layout, axis + "-Scale", ["linear", "log", "symlog", "logit"])
self.input_scale.link(axis + "scale", signal_target_changed)
self.input_font = TextPropertiesWidget(self.layout)
self.input_labelpad = NumberWidget(self.layout, axis + "-Labelpad", min=-999)
self.input_labelpad.link(axis + "axis.labelpad", signal_target_changed, direct=True)
self.button_ok = QtWidgets.QPushButton("Ok")
self.layout.addWidget(self.button_ok)
self.button_ok.clicked.connect(self.hide)
示例12: __init__
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def __init__(self, num="", *args, **kwargs):
QtWidgets.QWidget.__init__(self)
self.setWindowTitle("Figure %s" % num)
self.setWindowIcon(qta.icon("fa.bar-chart"))
self.layout = QtWidgets.QVBoxLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.setSpacing(0)
self.canvas = MatplotlibWidget(self, *args, **kwargs)
self.canvas.window = self
self.layout.addWidget(self.canvas)
self.toolbar = NavigationToolbar(self.canvas, self)
self.layout.addWidget(self.toolbar)
self.signal.connect(self.show)
示例13: __init__
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def __init__(self, parent: QtWidgets, canvas: Canvas):
""" A widget to display all curently used colors and let the user switch them.
Args:
parent: the parent widget
canvas: the figure's canvas element
"""
QtWidgets.QWidget.__init__(self)
# initialize color artist dict
self.color_artists = {}
# add update push button
self.button_update = QtWidgets.QPushButton(qta.icon("fa.refresh"), "update")
self.button_update.clicked.connect(self.updateColors)
# add color chooser layout
self.layout_right = QtWidgets.QVBoxLayout(self)
self.layout_right.addWidget(self.button_update)
self.layout_colors = QtWidgets.QVBoxLayout()
self.layout_right.addLayout(self.layout_colors)
self.layout_colors2 = QtWidgets.QVBoxLayout()
self.layout_right.addLayout(self.layout_colors2)
self.layout_buttons = QtWidgets.QVBoxLayout()
self.layout_right.addLayout(self.layout_buttons)
self.button_save = QtWidgets.QPushButton("Save Colors")
self.button_save.clicked.connect(self.saveColors)
self.layout_buttons.addWidget(self.button_save)
self.button_load = QtWidgets.QPushButton("Load Colors")
self.button_load.clicked.connect(self.loadColors)
self.layout_buttons.addWidget(self.button_load)
self.canvas = canvas
# add a text widget to allow easy copy and paste
self.colors_text_widget = QtWidgets.QTextEdit()
self.colors_text_widget.setAcceptRichText(False)
self.layout_colors2.addWidget(self.colors_text_widget)
self.colors_text_widget.textChanged.connect(self.colors_changed)
示例14: create_widget
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def create_widget():
widget = QWidget()
layout = QHBoxLayout()
widget.setLayout(layout)
widget.status = QLabel('ready...')
layout.addWidget(widget.status)
widget.show()
return widget
示例15: _get_timer_name
# 需要导入模块: from qtpy import QtWidgets [as 别名]
# 或者: from qtpy.QtWidgets import QWidget [as 别名]
def _get_timer_name(receiver: QWidget, event: QEvent) -> str:
"""Return a name for this event.
Parameters
----------
receiver : QWidget
The receiver of the event.
event : QEvent
The event name.
Returns
-------
str
The timer's name
Notes
-----
If no object we return <event_name>.
If there's an object we return <event_name>:<object_name>.
Combining the two names with a colon is our own made-up format. The name
will show up in chrome://tracing and our QtPerformance widget.
"""
event_str = EVENT_TYPES.as_string(event.type())
try:
# There may or may not be a receiver object name.
object_name = receiver.objectName()
except AttributeError:
# Ignore "missing objectName attribute" during shutdown.
object_name = None
if object_name:
return f"{event_str}:{object_name}"
# There was no object (pretty common).
return event_str