def __init__(self, parent=None, direction="ltr", rtf=False): """ Creates a new QPageWidget on given parent object. parent: QWidget parent direction: "ltr" -> Left To Right "ttb" -> Top To Bottom rtf: Return to first, if its True it flips to the first page when next page requested at the last page """ # First initialize, QPageWidget is based on QScrollArea QScrollArea.__init__(self, parent) # Properties for QScrollArea self.setFrameShape(QFrame.NoFrame) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setWidgetResizable(True) # Main widget, which stores all Pages in it self.widget = QWidget(self) # Layout based on QBoxLayout which supports Vertical or Horizontal layout if direction == "ltr": self.layout = QBoxLayout(QBoxLayout.LeftToRight, self.widget) self.__scrollBar = self.horizontalScrollBar() self.__base_value = self.width else: self.layout = QBoxLayout(QBoxLayout.TopToBottom, self.widget) self.__scrollBar = self.verticalScrollBar() self.__base_value = self.height self.layout.setSpacing(0) self.layout.setMargin(0) # Return to first self.__return_to_first = rtf # TMP_PAGE, its using as last page in stack # A workaround for a QScrollArea bug self.__tmp_page = Page(QWidget(self.widget)) self.__pages = [self.__tmp_page] self.__current = 0 self.__last = 0 # Set main widget self.setWidget(self.widget) # Animation TimeLine self.__timeline = QTimeLine() self.__timeline.setUpdateInterval(2) # Updates scrollbar position when frame changed self.__timeline.frameChanged.connect( lambda x: self.__scrollBar.setValue(x)) # End of the animation self.__timeline.finished.connect(self._animateFinished) # Initialize animation self.setAnimation() self.setDuration()
def __init__(self, parent=None): QTabWidget.__init__(self, parent) self.setTabBar(TabBarSupport(self)) self.setMovable(False) self.setTabsClosable(True) self.setDocumentMode(False) self.navigationButton = QPushButton( QIcon(getPath('iconDir', 'navigation.png')), "", self) self.navigationButton.setFlat(True) self.closeButton = QPushButton( QIcon(getPath('iconDir', 'navclose.png')), "", self) self.closeButton.setFlat(True) self.rightCornerWidget = QWidget(self) self.rightCornerWidgetLayout = QHBoxLayout(self.rightCornerWidget) self.rightCornerWidgetLayout.setMargin(0) self.rightCornerWidgetLayout.setSpacing(0) self.rightCornerWidgetLayout.addWidget(self.navigationButton) self.rightCornerWidgetLayout.addWidget(self.closeButton) self.setCornerWidget(self.rightCornerWidget, Qt.TopRightCorner) QObject.connect(self.navigationButton, SIGNAL("pressed()"), self.__evt_navigation) QObject.connect( self.closeButton, SIGNAL("clicked(bool)"), lambda: self.emit( SIGNAL("tabCloseRequested (int)"), self.currentIndex())) QObject.connect(self, SIGNAL("tabCloseRequested (int)"), self.__evt_close_tab_click) QObject.connect(self.tabBar(), SIGNAL('customContextMenuRequested(const QPoint &)'), self.__evt_showContextMenu)
def test1(self): class FT(QToolBar): def paintEvent(self, e): pass w = QMainWindow() ftt, ftb = FT(), FT() ftt.setFixedHeight(15) ftb.setFixedHeight(15) w.addToolBar(Qt.TopToolBarArea, ftt) w.addToolBar(Qt.BottomToolBarArea, ftb) f = dropshadow.DropShadowFrame() te = QTextEdit() c = QWidget() c.setLayout(QVBoxLayout()) c.layout().setContentsMargins(20, 0, 20, 0) c.layout().addWidget(te) w.setCentralWidget(c) f.setWidget(te) f.radius = 15 f.color = QColor(Qt.blue) w.show() self.singleShot(3000, lambda: f.setColor(Qt.red)) self.singleShot(4000, lambda: f.setRadius(30)) self.singleShot(5000, lambda: f.setRadius(40)) self.app.exec_()
def test_dock_standalone(self): widget = QWidget() layout = QHBoxLayout() widget.setLayout(layout) layout.addStretch(1) widget.show() dock = CollapsibleDockWidget() layout.addWidget(dock) list_view = QListView() list_view.setModel(QStringListModel(["a", "b"], list_view)) label = QLabel("A label. ") label.setWordWrap(True) dock.setExpandedWidget(label) dock.setCollapsedWidget(list_view) dock.setExpanded(True) self.app.processEvents() def toogle(): dock.setExpanded(not dock.expanded()) self.singleShot(2000, toogle) toogle() self.app.exec_()
def test_toolbox(self): w = QWidget() layout = QHBoxLayout() reg = registry_tests.small_testing_registry() qt_reg = QtWidgetRegistry(reg) triggered_actions = [] model = qt_reg.model() one_action = qt_reg.action_for_widget("one") box = WidgetToolBox() box.setModel(model) box.triggered.connect(triggered_actions.append) layout.addWidget(box) box.setButtonSize(QSize(50, 80)) w.setLayout(layout) w.show() one_action.trigger() box.setButtonSize(QSize(60, 80)) box.setIconSize(QSize(35, 35)) box.setTabButtonHeight(40) box.setTabIconSize(QSize(30, 30)) self.app.exec_()
def __init__(self, plugin, modelRoot): super(NeuroKitEditor, self).__init__(plugin) self._centralWidget = None #default.DefaultEditorWidget(None) self.modelRoot = modelRoot # self._centralWidget = NeuroKitEditorWidget.NeuroKitEditorWidget(modelRoot) self._menus = [] # self._propertyTable = MorphologyProperyTable() self._propertyTable = QWidget() self.__initMenus() self.__initToolBars() self.setModelRoot(modelRoot)
def __init__(self, sliderOrientation=None): super(QLabelSlider, self).__init__() self._slider = QSlider(sliderOrientation) self.setLayout(QVBoxLayout()) self._labelTicksWidget = QWidget(self) self._labelTicksWidget.setLayout(QHBoxLayout()) self._labelTicksWidget.layout().setContentsMargins(0, 0, 0, 0) self.layout().addWidget(self._slider) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().addWidget(self._labelTicksWidget)
def initUI(self): self.setGeometry(300, 300, 250, 150) self.setWindowTitle('pyv4l test') # top layout layout = QHBoxLayout() layout.addLayout(self.get_left_layout()) layout.addLayout(self.get_video_layout()) w = QWidget() w.setLayout(layout) self.setCentralWidget(w)
def initUI(self): cw = QWidget() self.setCentralWidget(cw) grid = QGridLayout() grid.setSpacing(15) # status bar self.statusBar().showMessage('Ready') font_label = QFont() font_label.setBold(True) ################ dicom reader rstart = 0 text_dcm = QLabel('DICOM reader') text_dcm.setFont(font_label) self.text_dcm_dir = QLabel('DICOM dir:') self.text_dcm_data = QLabel('DICOM data:') self.text_dcm_out = QLabel('output file:') grid.addWidget(text_dcm, rstart + 0, 1, 1, 4) grid.addWidget(self.text_dcm_dir, rstart + 1, 1, 1, 4) grid.addWidget(self.text_dcm_data, rstart + 2, 1, 1, 4) grid.addWidget(self.text_dcm_out, rstart + 3, 1, 1, 4) btn_dcmdir = QPushButton("Load DICOM", self) btn_dcmdir.clicked.connect(self.loadDcmDir) btn_dcmred = QPushButton("Organ Segmentation", self) btn_dcmred.clicked.connect(self.organSegmentation) btn_dcmcrop = QPushButton("Crop", self) btn_dcmcrop.clicked.connect(self.cropDcm) btn_dcmsave = QPushButton("Save DCM", self) btn_dcmsave.clicked.connect(self.saveDcm) grid.addWidget(btn_dcmdir, rstart + 4, 1) grid.addWidget(btn_dcmred, rstart + 4, 2) grid.addWidget(btn_dcmcrop, rstart + 4, 3) grid.addWidget(btn_dcmsave, rstart + 4, 4) hr = QFrame() hr.setFrameShape(QFrame.HLine) grid.addWidget(hr, rstart + 5, 0, 1, 6) # quit btn_quit = QPushButton("Quit", self) btn_quit.clicked.connect(self.quit) grid.addWidget(btn_quit, 24, 2, 1, 2) cw.setLayout(grid) self.setWindowTitle('liver-surgery') self.show()
def invoke(self): searchInput = QLineEdit() normalInput = QPlainTextEdit() normalInput.setMaximumHeight(100) searchBtn = QPushButton("Search") sayBtn = QPushButton("Hmm..") listTops = QWidget() layoutWidget = QGridLayout() layoutWidget.addWidget(searchInput, 1, 0) layoutWidget.addWidget(searchBtn, 1, 1) layoutWidget.addWidget(normalInput, 2, 0) layoutWidget.addWidget(sayBtn, 2, 1) layoutWidget.addWidget(listTops, 3, 0, 8, 1) self.setLayout(layoutWidget)
def low_res_layout(): layout = QVBoxLayout() layout.addWidget(QLabel("Overview")) # Raw X-windows canvas self.video_container = QWidget() # Allows for convenient keyboard control by clicking on the video self.video_container.setFocusPolicy(Qt.ClickFocus) w, h = 3264 / 4, 2448 / 4 self.video_container.setMinimumSize(w, h) self.video_container.resize(w, h) policy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.video_container.setSizePolicy(policy) layout.addWidget(self.video_container) return layout
def test_widgettoolgrid(self): w = QWidget() layout = QHBoxLayout() reg = registry_tests.small_testing_registry() qt_reg = QtWidgetRegistry(reg) triggered_actions1 = [] triggered_actions2 = [] model = qt_reg.model() data_descriptions = qt_reg.widgets("Constants") one_action = qt_reg.action_for_widget("one") actions = list(map(qt_reg.action_for_widget, data_descriptions)) grid = ToolGrid(w) grid.setActions(actions) grid.actionTriggered.connect(triggered_actions1.append) layout.addWidget(grid) grid = WidgetToolGrid(w) # First category ("Data") grid.setModel(model, rootIndex=model.index(0, 0)) self.assertIs(model, grid.model()) # Test order of buttons grid_layout = grid.layout() for i in range(len(actions)): button = grid_layout.itemAtPosition(i / 4, i % 4).widget() self.assertIs(button.defaultAction(), actions[i]) grid.actionTriggered.connect(triggered_actions2.append) layout.addWidget(grid) w.setLayout(layout) w.show() one_action.trigger() self.app.exec_()
def test_prop(self): w = QWidget() layout = QVBoxLayout() cb = QCheckBox("Check", w) sp = QSpinBox(w) le = QLineEdit(w) textw = QTextEdit(w, readOnly=True) textw.setProperty("checked_", False) textw.setProperty("spin_", 0) textw.setProperty("line_", "") textexpr = PropertyBindingExpr(r""" ("Check box is {0}\n" "Spin has value {1}\n" "Line contains {2}").format( "checked" if checked else "unchecked", spin, line) """, dict(checked=binding_for(cb, "checked"), spin=binding_for(sp, "value"), line=binding_for(le, "text")), ) layout.addWidget(cb) layout.addWidget(sp) layout.addWidget(le) layout.addWidget(textw) manager = BindingManager(submitPolicy=BindingManager.AutoSubmit) manager.bind(PropertyBinding(textw, "plainText", "textChanged"), textexpr) w.setLayout(layout) w.show() self.app.exec_()
def initializeOperationActions(self): self.showAllAction = QAction( KIcon(("applications-other", "package_applications")), i18n("All Packages"), self) self.connect(self.showAllAction, SIGNAL("triggered()"), lambda: self.cw.switchState(StateManager.ALL)) self.cw.stateTab.addTab( QWidget(), KIcon(("applications-other", "package_applications")), i18n("All Packages")) self.showInstallAction = QAction(KIcon(("list-add", "add")), i18n("Installable Packages"), self) self.connect(self.showInstallAction, SIGNAL("triggered()"), lambda: self.cw.switchState(StateManager.INSTALL)) self.cw.stateTab.addTab(QWidget(), KIcon(("list-add", "add")), i18n("Installable Packages")) self.showRemoveAction = QAction(KIcon(("list-remove", "remove")), i18n("Installed Packages"), self) self.connect(self.showRemoveAction, SIGNAL("triggered()"), lambda: self.cw.switchState(StateManager.REMOVE)) self.cw.stateTab.addTab(QWidget(), KIcon(("list-remove", "remove")), i18n("Installed Packages")) self.showUpgradeAction = QAction( KIcon(("system-software-update", "gear")), i18n("Updates"), self) self.connect(self.showUpgradeAction, SIGNAL("triggered()"), lambda: self.cw.switchState(StateManager.UPGRADE)) self.cw.stateTab.addTab(QWidget(), KIcon(("system-software-update", "gear")), i18n("Updates")) self.showPreferences = QAction( KIcon(("preferences-system", "package_settings")), i18n("Settings"), self) self.connect(self.showPreferences, SIGNAL("triggered()"), self.settingsDialog.show) self.actionHelp = QAction(KIcon("help"), i18n("Help"), self) self.actionHelp.setShortcuts(QKeySequence.HelpContents) self.connect(self.actionHelp, SIGNAL("triggered()"), self.showHelp) self.actionQuit = QAction(KIcon("exit"), i18n("Quit"), self) self.actionQuit.setShortcuts(QKeySequence.Quit) self.connect(self.actionQuit, SIGNAL("triggered()"), qApp.exit) self.cw.menuButton.setMenu(QMenu('MainMenu', self.cw.menuButton)) self.cw.menuButton.setIcon( KIcon(("preferences-system", "package_settings"))) self.cw.menuButton.menu().clear() self.cw.contentHistory.hide() self.cw.menuButton.menu().addAction(self.showPreferences) self.cw.menuButton.menu().addSeparator() self.cw.menuButton.menu().addAction(self.actionHelp) self.cw.menuButton.menu().addAction(self.actionQuit) self.cw._states = { self.cw.state.ALL: (0, self.showAllAction), self.cw.state.INSTALL: (1, self.showInstallAction), self.cw.state.REMOVE: (2, self.showRemoveAction), self.cw.state.UPGRADE: (3, self.showUpgradeAction) } self.showAllAction.setChecked(True) self.cw.checkUpdatesButton.hide() self.cw.checkUpdatesButton.setIcon(KIcon(("view-refresh", "reload"))) self.cw.showBasketButton.clicked.connect(self.cw.showBasket) # Little time left for the new ui self.menuBar().setVisible(False) self.cw.switchState(self.cw.state.ALL)
def test(self): window = QWidget() layout = QVBoxLayout() window.setLayout(layout) stack = stackedwidget.AnimatedStackedWidget() stack.transitionFinished.connect(self.app.exit) layout.addStretch(2) layout.addWidget(stack) layout.addStretch(2) window.show() widget1 = QLabel("A label " * 10) widget1.setWordWrap(True) widget2 = QGroupBox("Group") widget3 = QListView() self.assertEqual(stack.count(), 0) self.assertEqual(stack.currentIndex(), -1) stack.addWidget(widget1) self.assertEqual(stack.count(), 1) self.assertEqual(stack.currentIndex(), 0) stack.addWidget(widget2) stack.addWidget(widget3) self.assertEqual(stack.count(), 3) self.assertEqual(stack.currentIndex(), 0) def widgets(): return [stack.widget(i) for i in range(stack.count())] self.assertSequenceEqual([widget1, widget2, widget3], widgets()) stack.show() stack.removeWidget(widget2) self.assertEqual(stack.count(), 2) self.assertEqual(stack.currentIndex(), 0) self.assertSequenceEqual([widget1, widget3], widgets()) stack.setCurrentIndex(1) # wait until animation finished self.app.exec_() self.assertEqual(stack.currentIndex(), 1) widget2 = QGroupBox("Group") stack.insertWidget(1, widget2) self.assertEqual(stack.count(), 3) self.assertEqual(stack.currentIndex(), 2) self.assertSequenceEqual([widget1, widget2, widget3], widgets()) stack.transitionFinished.disconnect(self.app.exit) self.singleShot(2000, lambda: stack.setCurrentIndex(0)) self.singleShot(4000, lambda: stack.setCurrentIndex(1)) self.singleShot(6000, lambda: stack.setCurrentIndex(2)) self.app.exec_()