當前位置: 首頁>>代碼示例>>Python>>正文


Python QtWidgets.QWidget方法代碼示例

本文整理匯總了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) 
開發者ID:rgerum,項目名稱:pylustrator,代碼行數:27,代碼來源:QLinkableWidgets.py

示例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) 
開發者ID:napari,項目名稱:napari,代碼行數:19,代碼來源:qt_dims.py

示例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 
開發者ID:napari,項目名稱:napari,代碼行數:21,代碼來源:_magicgui.py

示例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."))) 
開發者ID:KmolYuan,項目名稱:Pyslvs-UI,代碼行數:26,代碼來源:about.py

示例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;") 
開發者ID:KmolYuan,項目名稱:Pyslvs-UI,代碼行數:24,代碼來源:rotatable.py

示例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 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:11,代碼來源:test_main.py

示例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 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:11,代碼來源:test_main.py

示例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 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:11,代碼來源:test_main.py

示例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 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:14,代碼來源:test_main.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:15,代碼來源:uiKLine.py

示例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) 
開發者ID:rgerum,項目名稱:pylustrator,代碼行數:39,代碼來源:QComplexWidgets.py

示例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) 
開發者ID:rgerum,項目名稱:pylustrator,代碼行數:16,代碼來源:matplotlibwidget.py

示例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) 
開發者ID:rgerum,項目名稱:pylustrator,代碼行數:41,代碼來源:QtGui.py

示例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 
開發者ID:napari,項目名稱:napari,代碼行數:10,代碼來源:multithreading_simple.py

示例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 
開發者ID:napari,項目名稱:napari,代碼行數:39,代碼來源:qt_event_timing.py


注:本文中的qtpy.QtWidgets.QWidget方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。