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, 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, scheme, parent): super(EditorSchemeDesigner, self).__init__(parent, Qt.Dialog) self.original_style = copy.copy(resources.CUSTOM_SCHEME) self._avoid_on_loading, self.saved, self._components = True, False, {} self.setWindowTitle(translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER) self.setMinimumSize(450, 480) self.setMaximumSize(500, 900) self.resize(450, 600) # all layouts and groupboxes group0 = QGroupBox(translations.TR_PROJECT_NAME) # scheme filename group1 = QGroupBox(translations.TR_PROJECT_PROPERTIES) # properties group2 = QGroupBox(translations.TR_PREVIEW) # quick preview thingy group0_hbox, group1_vbox = QHBoxLayout(group0), QVBoxLayout(group1) this_dialog_vbox, group2_vbox = QVBoxLayout(self), QVBoxLayout(group2) self._grid, scrollArea, frame = QGridLayout(), QScrollArea(), QFrame() # widgets self.line_name, btnSave = QLineEdit(), QPushButton( translations.TR_SAVE) self.line_name.setPlaceholderText(getuser().capitalize() + "s_scheme") group0_hbox.addWidget(self.line_name) group0_hbox.addWidget(btnSave) self.connect(btnSave, SIGNAL("clicked()"), self.save_scheme) _demo = "<center>" + ascii_letters # demo text for preview self.preview_label1, self.preview_label2 = QLabel(_demo), QLabel(_demo) group2_vbox.addWidget(self.preview_label1) group2_vbox.addWidget(self.preview_label2) # rows titles self._grid.addWidget(QLabel("<b>" + translations.TR_PROJECT_NAME), 0, 0) self._grid.addWidget(QLabel("<b>" + translations.TR_CODE), 0, 1) self._grid.addWidget( QLabel("<b>" + translations.TR_EDITOR_SCHEME_PICK_COLOR), 0, 2) # fill rows for key in sorted(tuple(resources.COLOR_SCHEME.keys())): self.add_item(key, scheme) self.preview_label1.setStyleSheet('background:transparent') self.preview_label2.setStyleSheet('color: transparent') # fill the scroll area frame.setLayout(self._grid) scrollArea.setWidget(frame) group1_vbox.addWidget(scrollArea) # put groups on the dialog this_dialog_vbox.addWidget(group1) this_dialog_vbox.addWidget(group2) this_dialog_vbox.addWidget(group0) self._avoid_on_loading = self._modified = False
def event(self, event): """ Overrides the main event handler to catch resize events """ # Catch Resize event if event.type() == QEvent.Resize: # Update each page size limits to mainwidget's new size for page in self.__pages: page.widget.setMinimumSize(self.size()) page.widget.setMaximumSize(self.size()) # Update viewport size limits to mainwidget's new size # It's a workaround for QScrollArea updateGeometry bug self.viewport().setMinimumSize(self.size()) self.viewport().setMaximumSize(self.size()) # Update scrollbar position for current page self.__scrollBar.setValue(self.__current * self.__base_value()) # Return the Event return QScrollArea.event(self, event)