Python qtpy.QtWidgets.QWidget() Examples

The following are 30 code examples of qtpy.QtWidgets.QWidget(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module qtpy.QtWidgets , or try the search function .
Example #1
Source File: about.py    From Pyslvs-UI with GNU Affero General Public License v3.0 6 votes vote down vote up
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."))) 
Example #2
Source File: rotatable.py    From Pyslvs-UI with GNU Affero General Public License v3.0 6 votes vote down vote up
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;") 
Example #3
Source File: _magicgui.py    From napari with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example #4
Source File: qt_dims.py    From napari with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #5
Source File: QLinkableWidgets.py    From pylustrator with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #6
Source File: QLinkableWidgets.py    From pylustrator with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, layout: QtWidgets.QLayout, text: str, values: Sequence):
        """ A combo box widget with a label

        Args:
            layout: the layout to which to add the widget
            text: the label text
            values: the possible values of the combo 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.values = values

        self.input1 = QtWidgets.QComboBox()
        self.input1.addItems(values)
        self.layout.addWidget(self.input1)

        self.input1.currentIndexChanged.connect(self.valueChangeEvent)
        self.layout.addWidget(self.input1) 
Example #7
Source File: QLinkableWidgets.py    From pylustrator with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, layout: QtWidgets.QLabel, text: str):
        """ a widget that contains a checkbox with a label

        Args:
            layout: the layout to which to add the widget
            text: the label text
        """
        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.input1 = QtWidgets.QCheckBox()
        self.input1.setTristate(False)
        self.input1.stateChanged.connect(self.onStateChanged)
        self.layout.addWidget(self.input1) 
Example #8
Source File: test_main.py    From P4VFX with MIT License 5 votes vote down vote up
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 
Example #9
Source File: FileRevisionWindow.py    From P4VFX with MIT License 5 votes vote down vote up
def setRevisionTableColumn(self, row, column, value, icon=None, isLongText=False):
        value = str(value)

        widget = QtWidgets.QWidget()
        layout = QtWidgets.QHBoxLayout()
        layout.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignHCenter)

        # Use a QLineEdit to allow the text to be copied if the data is large
        if isLongText:
            textLabel = QtWidgets.QLineEdit()
            textLabel.setText(value)
            textLabel.setCursorPosition(0)
            textLabel.setReadOnly(True)
            textLabel.setStyleSheet("QLineEdit { border: none }")
        else:
            textLabel = QtWidgets.QLabel(value)
            textLabel.setStyleSheet("QLabel { border: none } ")

        # layout.setContentsMargins(4, 0, 4, 0)
        
        if icon:
            iconPic = QtGui.QPixmap(icon)
            iconPic = iconPic.scaled(16, 16)
            iconLabel = QtWidgets.QLabel()
            iconLabel.setPixmap(iconPic)
            layout.addWidget(iconLabel)
        layout.addWidget(textLabel)

        widget.setLayout(layout)

        self.tableWidget.setCellWidget(row, column, widget) 
Example #10
Source File: test_main.py    From P4VFX with MIT License 5 votes vote down vote up
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 
Example #11
Source File: test_main.py    From P4VFX with MIT License 5 votes vote down vote up
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 
Example #12
Source File: test_main.py    From P4VFX with MIT License 5 votes vote down vote up
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 
Example #13
Source File: test_main.py    From P4VFX with MIT License 5 votes vote down vote up
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 
Example #14
Source File: test_main.py    From P4VFX with MIT License 5 votes vote down vote up
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 
Example #15
Source File: thread.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, parent: QWidget):
        super(BaseThread, self).__init__(parent)
        self.finished.connect(self.deleteLater)
        self.is_stop = False 
Example #16
Source File: thread.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, nl: int, nj: int, parent: QWidget):
        super(LinkThread, self).__init__(parent)
        self.nl = nl
        self.nj = nj 
Example #17
Source File: thread.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, jobs: Sequence[QTreeWidgetItem], degenerate: int, parent: QWidget):
        super(GraphThread, self).__init__(parent)
        self.jobs = jobs
        self.degenerate = degenerate 
Example #18
Source File: chart.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, parent: QWidget, title: str, row: int = 1, col: int = 1,
                 polar: bool = False):
        super(DataChartDialog, self).__init__(parent)
        self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint
                            & ~Qt.WindowContextHelpButtonHint)
        self.setWindowTitle(title)
        self.setModal(True)
        layout = QVBoxLayout(self)
        self._chart = DataChart(self, row, col, polar)
        layout.addWidget(self._chart) 
Example #19
Source File: canvas.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, parent: QWidget):
        """Set the parameters for drawing."""
        super(BaseCanvas, self).__init__(parent)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.setFocusPolicy(Qt.StrongFocus)
        self.setMouseTracking(True)
        self.painter = QPainter()
        # Origin coordinate
        self.ox = self.width() / 2
        self.oy = self.height() / 2
        # Canvas zoom rate
        self.zoom = 1.
        # Joint size
        self.joint_size = 5
        # Canvas line width
        self.link_width = 3
        self.path_width = 3
        # Font size
        self.font_size = 15
        # Show point mark or dimension
        self.show_ticks = _TickMark.SHOW
        self.show_point_mark = True
        self.show_dimension = True
        # Path track
        self.path = _PathOption()
        # Path solving
        self.ranges = {}
        self.target_path = {}
        self.show_target_path = False
        # Background
        self.background = QImage()
        self.background_opacity = 1.
        self.background_scale = 1.
        self.background_offset = QPointF(0, 0)
        # Monochrome mode
        self.monochrome = False
        # Grab mode
        self.__grab_mode = False 
Example #20
Source File: canvas.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, parent: QWidget):
        super(AnimationCanvas, self).__init__(parent)
        self.no_mechanism = False 
Example #21
Source File: canvas.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, parent: QWidget):
        """Input parameters and attributes."""
        super(PreviewCanvas, self).__init__(parent)
        self.graph = Graph([])
        self.cus = {}
        self.same = {}
        self.pos = {}
        self.status = {}
        # Additional attributes
        self.grounded = -1
        self.driver = set()
        self.target = set()
        self.clear() 
Example #22
Source File: graph1.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def test(self):
        tab1 = QtWidgets.QWidget()
        scrollArea = QtWidgets.QScrollArea(tab1)
        scrollArea.setMinimumSize(984,550)
        scrollArea.setWidgetResizable(True)
        labelsContainer = QWidget()
        labelsContainer.setMinimumSize(0,1500)
        scrollArea.setWidget(labelsContainer)
        layout = QtWidgets.QVBoxLayout(labelsContainer)
        time = ['2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00']
        value = [1.2, 2, 1, 4]
        xdict = dict(enumerate(time))
        ticks = [list(zip(range(4), tuple(time)))]
        vb = CustomViewBox()
        plt = pg.PlotWidget(title="标题这里填写",viewBox=vb)
        plt.setBackground(background=None)
        plt.plot(list(xdict.keys()), value)
        plt.getPlotItem().getAxis("bottom").setTicks(ticks)
        temp = QtWidgets.QWidget()
        temp.setMinimumSize(900,300)
        temp.setMaximumSize(900,300)
        layout1 = QtWidgets.QVBoxLayout(temp)
        layout1.addWidget(plt)
        layout.addWidget(temp)
        spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        layout.addItem(spacerItem)
        self.tabWidget.addTab(tab1, '这里tabWidget修改标签') 
Example #23
Source File: testGraphAnalysis.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def test(self):

        tab1 = QtWidgets.QWidget()
        scrollArea = QtWidgets.QScrollArea(tab1)
        scrollArea.setMinimumSize(650,550)
        scrollArea.setWidgetResizable(True)

        labelsContainer = QWidget()
        labelsContainer.setMinimumSize(0,3000+200)
        scrollArea.setWidget(labelsContainer)
        layout = QtWidgets.QVBoxLayout(labelsContainer)

        time = ['2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00', '2019-04-20 08:09:00']
        value = [1.2, 2, 1, 4]
        xdict = dict(enumerate(time))
        ticks = [list(zip(range(4), tuple(time)))]
        for i in range(11):
            vb1 = CustomViewBox()
            plt1 = pg.PlotWidget(title="Basic array plotting%s"%i, viewBox=vb1)
            plt1.resize(500, 500)
            plt1.setBackground(background=None)
            plt1.plot(list(xdict.keys()), value)
            plt1.getPlotItem().getAxis("bottom").setTicks(ticks)
            temp1 = QtWidgets.QWidget()
            temp1.setMinimumSize(600, 300)
            temp1.setMaximumSize(600, 300)
            layout2 = QtWidgets.QVBoxLayout(temp1)
            layout2.addWidget(plt1)
            layout.addWidget(temp1)
        spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        layout.addItem(spacerItem)
        # print(layout.count())
        self.tabWidget.addTab(tab1, '12')
        for i in range(self.tabWidget.count()):
            self.tabWidget.widget(i) 
Example #24
Source File: test_main.py    From qtpy with MIT License 5 votes vote down vote up
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 
Example #25
Source File: test_main.py    From qtpy with MIT License 5 votes vote down vote up
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 
Example #26
Source File: test_main.py    From qtpy with MIT License 5 votes vote down vote up
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 
Example #27
Source File: test_main.py    From qtpy with MIT License 5 votes vote down vote up
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 
Example #28
Source File: base_module_widget.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def init_main_layout(self, orientation='horizontal'):
        self.root_layout = QtWidgets.QHBoxLayout()
        self.main_widget = QtWidgets.QWidget()
        self.root_layout.addWidget(self.main_widget)
        if orientation == "vertical":
            self.main_layout = QtWidgets.QVBoxLayout()
        else:
            self.main_layout = QtWidgets.QHBoxLayout()
        self.main_widget.setLayout(self.main_layout)
        self.setLayout(self.root_layout) 
Example #29
Source File: QtGui.py    From pylustrator with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #30
Source File: test_main.py    From vnpy_crypto with MIT License 5 votes vote down vote up
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