def __init__(self, parent: QtWidgets.QBoxLayout, stretch, *args, **kwargs): super(VideoLabel, self).__init__(*args, **kwargs) self.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored) self.setScaledContents(True) parent.addWidget(self, stretch=stretch)
def _init_content(self, direction, collapsed): content = QFrame(self) content_layout = QBoxLayout(direction) content_layout.setAlignment(Qt.AlignTop) content.setLayout(content_layout) content.setVisible(not collapsed) return content
def __init__(self): QWidget.__init__(self, flags=Qt.Widget) # 레이아웃 선언 및 Form Widget에 설정 self.layout_1 = QBoxLayout(QBoxLayout.LeftToRight, self) self.layout_2 = QBoxLayout(QBoxLayout.LeftToRight) self.layout_3 = QBoxLayout(QBoxLayout.TopToBottom) # 부모 레이아웃에 자식 레이아웃을 추가 self.layout_1.addLayout(self.layout_2) self.layout_1.addLayout(self.layout_3) self.web = QWebEngineView() self.pb_1 = QPushButton("요청하기") self.pb_2 = QPushButton("밝기지도") self.pb_3 = QPushButton("길찾기") # self.te_1 = QTextEdit() # Web과 통신할 수 있게 채널링 channel = QWebChannel(self.web.page()) self.web.page().setWebChannel(channel) self.handler = CallHandler() # 반드시 인스턴스 변수로 사용해야 한다. channel.registerObject('handler', self.handler) # js에서 불리울 이름 self.setLayout(self.layout_1) self.init_widget()
def __init__(self, title, parent=None): super(ServoControls, self).__init__(title, parent) self.slider = QSlider(Qt.Horizontal) self.slider.setFocusPolicy(Qt.StrongFocus) self.slider.setTickPosition(QSlider.TicksBothSides) self.slider.setTickInterval(10) self.slider.setSingleStep(1) self.dial = QDial() self.dial.setFocusPolicy(Qt.StrongFocus) self.dial.setNotchesVisible(True) self.lcd_display = QLCDNumber() self.lcd_display.display(22) self.slider.valueChanged.connect(self.dial.setValue) self.dial.valueChanged.connect(self.lcd_display.display) self.dial.valueChanged.connect(self.slider.setValue) self.dial.valueChanged.connect(self.valueChanged) boxLayout = QBoxLayout(QBoxLayout.TopToBottom) boxLayout.addWidget(self.slider) boxLayout.addWidget(self.dial) boxLayout.addWidget(self.lcd_display) boxLayout.setStretchFactor(self.dial, 20) self.setLayout(boxLayout) self.setMinimum(0) self.setMaximum(100) self.dial.setWrapping(True)
def __init__(self, widget, aspectRatio): super(AspectRatioWidget, self).__init__() self.layout = QBoxLayout(QBoxLayout.LeftToRight, self) self.layout.addItem(QSpacerItem(0, 0)) self.layout.addWidget(widget) self.layout.addItem(QSpacerItem(0, 0)) self.setAspectRatio(aspectRatio)
def __init__(self): super().__init__() # information widget self.plotWidget = VariantPlotWidget() self.infoWidget = VariantInfoWidget() # splitter settings splitter = QSplitter(Qt.Horizontal) splitter.addWidget(self.plotWidget) splitter.addWidget(self.infoWidget) splitter.setStretchFactor(0, 3) splitter.setStretchFactor(1, 1) # layout layout = QBoxLayout(QBoxLayout.TopToBottom) layout.addWidget(splitter) self.setLayout(layout) # connect signals self.plotWidget.curvePlotted.connect(self.infoWidget.updateResults) self.plotWidget.plotReady.connect(self.infoWidget.showResults) self.plotWidget.cleared.connect(self.infoWidget.clear) self.infoWidget.legendChanged.connect(self.plotWidget.paintCalculation) # translate the graphical user interface self.retranslateUi()
def init_widget(self): self.setWindowTitle("Hello World") widget_laytout = QBoxLayout(QBoxLayout.LeftToRight) group = QGroupBox() box = QBoxLayout(QBoxLayout.TopToBottom) group.setLayout(box) group.setTitle("Buttons") widget_laytout.addWidget(group) fruits = [ "Buttons in GroupBox", "TextBox in GroupBox", "Label in GroupBox", "TextEdit" ] view = QListView(self) model = QStandardItemModel() for f in fruits: model.appendRow(QStandardItem(f)) view.setModel(model) box.addWidget(view) self.stk_w.addWidget(Widget_1()) self.stk_w.addWidget(Widget_2()) self.stk_w.addWidget(Widget_3()) self.stk_w.addWidget(QTextEdit()) widget_laytout.addWidget(self.stk_w) self.setLayout(widget_laytout) view.clicked.connect(self.slot_clicked_item)
def init_ui(self): self.setMinimumWidth(500) self.setMinimumHeight(400) layout = QBoxLayout(QBoxLayout.TopToBottom) self.setLayout(layout) self.lb_1.setPixmap(self.pixmap) layout.addWidget(self.lb_1)
def __init__(self, labels): QWidget.__init__(self) self.labels = labels self.layout = QBoxLayout(QBoxLayout.LeftToRight) for label in labels.labels: self.layout.addWidget(label) self.setLayout(self.layout)
def __init__(self, urls, toggle_sequence): super(MainWidget, self).__init__() proxy = proxy_module.Proxy() proxy.start_monitoring_daemon() self._captive_portal_url = '' self._urls = cycle(urls) self._current_url = next(self._urls) self._browser_widget = browser_widget.BrowserWidget( self._current_url, proxy.get_current) self._is_captive_portal_visible = False self._captive_portal_message = captive_portal_message.CaptivePortalMessage( self._toggle_captive_portal) self._layout = QBoxLayout(QBoxLayout.BottomToTop) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self._layout.addWidget(self._browser_widget) # Start captive portal when state is initialized self._captive_portal = captive_portal.CaptivePortal( proxy.get_current, self.set_captive_portal_url) self._captive_portal.start_monitoring_daemon() QShortcut(toggle_sequence, self).activated.connect(self._load_next_url) self.setLayout(self._layout) self.show()
def __init__(self): QWidget.__init__(self, flags=Qt.Widget) self.setWindowTitle("ItemView QListView") self.setFixedWidth(310) self.setFixedHeight(200) data = [ {"type": "Sword", "objects": ["Long Sword", "Short Sword"], "picture": "sword.png"}, {"type": "Shield", "objects": ["Wood Shield", "iron Shied"], "picture": "shield.png"}, ] self.layout = QBoxLayout(QBoxLayout.LeftToRight, self) self.setLayout(self.layout) # QTreeView 생성 및 설정 view = QTreeView(self) view.setEditTriggers(QAbstractItemView.DoubleClicked) self.model = Model(data) view.setModel(self.model) self.layout.addWidget(view) # 그림을 띄울 QLabel 생성 self.lb = QLabel() self.lb.setFixedSize(50, 50) self.layout.addWidget(self.lb) # 뷰 클릭시 발생하는 시그널 # 뷰를 클릭하면 QModelIndex를 넘겨준다. view.clicked.connect(self.slot_show_picture)
class Form(QWidget): def __init__(self): QWidget.__init__(self, flags=Qt.Widget) # 배치될 위젯 변수 선언 self.lb_1 = QLabel() self.lb_2 = QLabel() self.pb_1 = QPushButton() self.pb_2 = QPushButton() # 레이아웃 선언 및 Form Widget에 설정 self.layout_1 = QBoxLayout(QBoxLayout.LeftToRight, self) self.setLayout(self.layout_1) self.init_widget() def init_widget(self): self.setWindowTitle("Layout Basic") self.setFixedWidth(640) # 라벨1의 설정 및 레이아웃 추가 self.lb_1.setText("Label 1") self.lb_1.setStyleSheet("background-color: yellow") self.pb_1.setText("Button 1") self.layout_1.addWidget(self.lb_1) self.layout_1.addWidget(self.pb_1) # 라벨2의 설정 및 레이아웃 추가 self.lb_2.setText("Label 2") self.lb_2.setStyleSheet("background-color: red") self.pb_2.setText("Button 2") self.layout_1.addWidget(self.lb_2) self.layout_1.addWidget(self.pb_2)
def init_widget(self): self.setWindowTitle("Timer") form_lbx = QBoxLayout(QBoxLayout.TopToBottom, parent=self) self.setLayout(form_lbx) self.th.change_value.connect(self.pgsb.setValue) form_lbx.addWidget(self.pgsb)
def __init__(self, viewport): super().__init__() self.viewport = viewport self.moduleName = "QViewportHeader" self.setContentsMargins(0, 0, 0, 0) boxLayout = QBoxLayout(QBoxLayout.LeftToRight) boxLayout.setContentsMargins(0, 0, 0, 0) boxLayout.setSpacing(0) self.setLayout(boxLayout) titleBtn = QToolButton() titleBtn.setAutoRaise(True) titleBtn.setToolButtonStyle(Qt.ToolButtonTextOnly) titleBtn.setPopupMode(QToolButton.InstantPopup) self.titleBtn = titleBtn pivotSnapping = QToolButton() pivotSnapping.setToolTip("Pivot Snapping") pivotSnapping.setAutoRaise(True) pivotSnapping.setCheckable(True) self.pivotSnapping = pivotSnapping boxLayout.addWidget(titleBtn, 1) boxLayout.addStretch(1)
def initUI(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.button = QPushButton("Iniciar Simulador Z80") self.button1 = QPushButton() self.button2 = QPushButton() self.button3 = QPushButton() self.button4 = QPushButton() self.container = QWidget() self.layout = QGridLayout() self.layout.setColumnStretch(0, 6) self.layout.setColumnStretch(2, 2) self.layout.setRowStretch(0,2) self.layout.setRowStretch(2,6) QPushButton("Iniciar Simulador Z80") self.layout.addWidget(self.button, 1,1) self.container.setLayout(self.layout) self.layoutPrincipal = QBoxLayout(0) self.layoutPrincipal.addWidget(self.container) self.setLayout(self.layoutPrincipal) self.button.setStyleSheet("border:2px solid #000; border-radius: px;font-size: 29px;font-weight: bold;padding:15px") self.button.pressed.connect(self.IniciarInterfaz) qtRectangle = self.frameGeometry() centerPoint = QDesktopWidget().availableGeometry().center() qtRectangle.moveCenter(centerPoint) self.move(qtRectangle.topLeft()) self.setMinimumWidth(1090) self.setMinimumHeight(600) self.setMaximumWidth(1090) self.setMaximumHeight(600)
class GUI(QDialog): def __init__(self, settings): super(QDialog, self).__init__() self.setWindowTitle("Settings") self.setWindowIcon(QIcon('ui/icon.png')) self.setModal(True) self.setWindowFlags(Qt.WindowStaysOnTopHint) self._button_box = QDialogButtonBox( QDialogButtonBox.Ok ) self._button_box.button(QDialogButtonBox.Ok).clicked.connect(self.accept) self._tabs = QTabWidget() self._layout = QBoxLayout(QBoxLayout.TopToBottom) self._layout.addWidget(self._tabs) self._layout.addWidget(self._button_box) self.setLayout(self._layout) # setup tabs self.tab_list = {} self.widgets = {} # general tab general_tab = GeneralTab(settings) self._tabs.addTab(general_tab, general_tab.get_title()) characters_tab = CharactersTab(settings) self._tabs.addTab(characters_tab, characters_tab.get_title()) def set_show_tab(self, tab): if tab == "characters": self._tabs.setCurrentIndex(1)
class myForm(QWidget): def __init__(self): QWidget.__init__(self, flags=Qt.Widget) self.lb_1 = QLabel() self.lb_2 = QLabel() self.pb_1 = QPushButton() self.pb_2 = QPushButton() self.layout_1 = QBoxLayout(QBoxLayout.LeftToRight, self) self.setLayout(self.layout_1) self.init_widget() def init_widget(self): self.setWindowTitle("Layout exercise application") self.setFixedWidth(640) self.lb_1.setText("Label 1") self.lb_1.setStyleSheet("background-color: blue") self.pb_1.setText("Button 1") self.layout_1.addWidget(self.lb_1) self.layout_1.addWidget(self.pb_1) self.layout_1.addWidget(self.lb_2) self.layout_1.addWidget(self.pb_2) self.lb_2.setText("Label 99") self.lb_2.setStyleSheet("background-color: red") self.pb_2.setText("Button 99")
def init_widget(self): self.setWindowTitle("Hello World") self.setGeometry(10, 10, 100, 50) self.label = QLabel() layout = QBoxLayout(QBoxLayout.TopToBottom) layout.addWidget(self.label) self.setLayout(layout)
class QPushButtonWidgetForm(QWidget): def __init__(self): QWidget.__init__(self, flags=Qt.Widget) self.setWindowTitle(__appname__) self.btn_push = QPushButton() self.edt_number = QLineEdit() self.layout = QBoxLayout(QBoxLayout.TopToBottom, self) self.setLayout(self.layout) self.init_widget() def init_widget(self): self.setWindowTitle("QPushButton Shortcut") self.click_cnt = 0 self.edt_number.setText(str(self.click_cnt)) self.btn_push.setText("더하기 단축키(Alt + F7)") self.btn_push.pressed.connect(self.buttonClicked) self.btn_push.setShortcut("Alt+F7") self.layout.addWidget(self.edt_number) self.layout.addWidget(self.btn_push) def buttonClicked(self): self.click_cnt += 1 self.edt_number.setText(str(self.click_cnt))
def init_widget(self): self.setWindowTitle("Serial Controller") layout = QBoxLayout(QBoxLayout.TopToBottom, parent=self) grid_box = QGridLayout() grid_box.addWidget(QLabel(self.tr("Port")), 0, 0) grid_box.addWidget(self.cb_port, 0, 1) grid_box.addWidget(QLabel(self.tr("Baud Rate")), 1, 0) grid_box.addWidget(self.cb_baud_rate, 1, 1) grid_box.addWidget(QLabel(self.tr("Data Bits")), 2, 0) grid_box.addWidget(self.cb_data_bits, 2, 1) grid_box.addWidget(QLabel(self.tr("Flow Control")), 3, 0) grid_box.addWidget(self.cb_flow_control, 3, 1) grid_box.addWidget(QLabel(self.tr("Parity")), 4, 0) grid_box.addWidget(self.cb_parity, 4, 1) grid_box.addWidget(QLabel(self.tr("Stop Bits")), 5, 0) grid_box.addWidget(self.cb_stop_bits, 5, 1) self._fill_serial_info() self.gb.setLayout(grid_box) layout.addWidget(self.gb) self.setLayout(layout)
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()
class Form(QWidget): def __init__(self): QWidget.__init__(self, flags=Qt.Widget) self.setWindowTitle("ItemView QTreeView") self.setFixedWidth(310) self.setFixedHeight(200) data = [{ "name": "Mouse Action", "icon": "assets/mouse.png", "objects": [ { "name": "Click", "icon": "assets/network.png", "objects": None }, { "name": "Double Click", "icon": "assets/mail.png", "objects": None }, ] }, { "name": "Keyboard", "icon": "assets/keyboard.png", "objects": [ { "name": "Send Hotkey", "icon": "assets/earth.png", "objects": None }, { "name": "Type", "icon": "assets/folder.png", "objects": None }, ] }] self.layout = QBoxLayout(QBoxLayout.LeftToRight, self) self.setLayout(self.layout) # QTreeView 생성 및 설정 view = QTreeView(self) # QTreeView 스타일시트 설정 view.setStyleSheet(open("./ItemViews_QTreeView_03_style.css").read()) view.setAlternatingRowColors(True) # 라인별 교차색 self.model = Model(data) view.setModel(self.model) self.layout.addWidget(view) # 그림을 띄울 QLabel 생성 self.lb = QLabel() self.lb.setFixedSize(50, 50) self.layout.addWidget(self.lb)
def __init__(self): QWidget.__init__(self, flags=Qt.Widget) self.setWindowTitle(__appname__) self.btn_push = QPushButton() self.edt_number = QLineEdit() self.layout = QBoxLayout(QBoxLayout.TopToBottom, self) self.setLayout(self.layout) self.init_widget()
def __init__(self, parent: QtWidgets.QBoxLayout, stretch, vd, tp, *args, **kwargs): super().__init__(*args, **kwargs) self._initLayout() self._initRequestModule(vd, tp) parent.addLayout(self, stretch)
def init_widget(self): self.setWindowTitle("Signal Slot") form_lbx = QBoxLayout(QBoxLayout.TopToBottom, parent=self) self.setLayout(form_lbx) self.sd.valueChanged.connect(lambda v: self.lb.setText(str(v))) form_lbx.addWidget(self.sd) form_lbx.addWidget(self.lb)
def kon(self, link): self.browser = QWebEngineView() self.browser.setUrl(QUrl(link)) self.qwerty = QBoxLayout(QBoxLayout.LeftToRight, self) self.qwerty.addWidget(self.browser) self.qwerty.stretch(1) return self.qwerty
def __init__(self, parent): super(PDFList, self).__init__() self.doc = None self.doc_window = None self.parent = parent self.addButton = QPushButton("&Add PDF") self.grid = QGridLayout() self.layout = QBoxLayout(QBoxLayout.TopToBottom)
def init_widget(self): self.setWindowTitle("Hello World") form_lbx = QBoxLayout(QBoxLayout.TopToBottom, parent=self) self.setLayout(form_lbx) te = QTextEdit() form_lbx.addWidget(te)
def init_widget(self): self.setWindowTitle("Custom Signal") form_lbx = QBoxLayout(QBoxLayout.TopToBottom, parent=self) self.setLayout(form_lbx) self.tic_gen.Tic.connect(lambda: self.te.insertPlainText( time.strftime("[%H:%M:%S] Tic!\n"))) form_lbx.addWidget(self.te)
def __init__(self): QWidget.__init__(self, flags=Qt.Widget) # 배치될 위젯 변수 선언 self.pb_1 = QPushButton() self.pb_2 = QPushButton() # 레이아웃 선언 및 Form Widget에 설정 self.layout_1 = QBoxLayout(QBoxLayout.TopToBottom, self) self.setLayout(self.layout_1) self.init_widget()
def init_widget(self): self.setWindowTitle("Custom Signal") form_lbx = QBoxLayout(QBoxLayout.TopToBottom, parent = self) self.setLayout(form_lbx) self.pb.clicked.connect(self.count) form_lbx.addWidget(self.lb) form_lbx.addWidget(self.pb)
def __init__(self, area, orientation): super().__init__() self.area = area self.orientation = orientation self.content = None self.layout_ = QBoxLayout(QBoxLayout.LeftToRight if ( orientation == Qt.Horizontal) else QBoxLayout.TopToBottom) self.layout_.setContentsMargins(0, 0, 0, 0) self.layout_.setSpacing(0)
def __init__(self, algorithm): super(GroupOfSliders, self).__init__() GroupOfSliderssLayout = QBoxLayout(QBoxLayout.TopToBottom) GroupOfSliders.setFixedHeight(self, 300) for slider in algorithm.integer_sliders: GroupOfSliderssLayout.addWidget( SliderWidget(slider.name, slider.lower, slider.upper, slider.step_size, slider.default, False)) for slider in algorithm.float_sliders: GroupOfSliderssLayout.addWidget( SliderWidget(slider.name, slider.lower, slider.upper, slider.step_size, slider.default, True)) for checkbox in algorithm.checkboxes: GroupOfSliderssLayout.addWidget( CheckBoxWidget(checkbox.name, checkbox.default)) for dropdown in algorithm.drop_downs: GroupOfSliderssLayout.addWidget( ComboBoxWidget(dropdown.name, dropdown.options)) self.setLayout(GroupOfSliderssLayout)
class ComboBoxWidget(QGroupBox): """ This is the combobox widget as it is shown in the settings panel of the GUI. It gets initialized with a name With self.valueChanged on can connect a pyqt slot with the combobox pyqtSignal. """ def __init__(self, name, options, slot=None, default=None): super(ComboBoxWidget, self).__init__() self.activated = pyqtSignal() # ComboBox itself self.combobox = QtWidgets.QComboBox() self.combobox.orientationCombo = PyQt5.QtWidgets.QComboBox() self.combobox.setFixedWidth(220) # Label self.label = QtWidgets.QLabel() self.label.setText(name + ": ") self.SingleCheckBoxLayout = QBoxLayout(QBoxLayout.LeftToRight) self.SingleCheckBoxLayout.addWidget(self.label) self.SingleCheckBoxLayout.addWidget(self.combobox, Qt.AlignRight) self.setLayout(self.SingleCheckBoxLayout) self.setFixedHeight(70) self.setFlat(True) # options for i in options: self.add_item(i) if default is not None: index = self.combobox.findText(default) if index != -1: self.combobox.setCurrentIndex(index) if slot is not None: self.combobox.activated.connect(slot) def add_item(self, option, image=None): """ Args: | *option*: A string option refers to an entry which can be selected in the combobox later. | *image*: An optional icon that can be shown combobox. """ if image is None: self.combobox.addItem(option) else: self.combobox.addItem(QIcon(image), option)
def __init__(self, actions=None, parent=None, direction=QBoxLayout.LeftToRight): QWidget.__init__(self, parent) self.actions = [] self.buttons = [] layout = QBoxLayout(direction) layout.setContentsMargins(0, 0, 0, 0) self.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) if actions is not None: for action in actions: self.addAction(action) self.setLayout(layout)
def __init__(self): super(GroupOfImages, self).__init__() self.GroupOfImagesLayout = QBoxLayout(QBoxLayout.TopToBottom) GroupOfImages.setFixedHeight(self, 300) GroupOfImages.setFixedWidth(self, 300) self.height = 300
def __init__(self, name, options, slot=None, default=None): super(ComboBoxWidget, self).__init__() self.activated = pyqtSignal() # ComboBox itself self.combobox = QtWidgets.QComboBox() self.combobox.orientationCombo = PyQt5.QtWidgets.QComboBox() self.combobox.setFixedWidth(220) # Label self.label = QtWidgets.QLabel() self.label.setText(name + ": ") self.SingleCheckBoxLayout = QBoxLayout(QBoxLayout.LeftToRight) self.SingleCheckBoxLayout.addWidget(self.label) self.SingleCheckBoxLayout.addWidget(self.combobox, Qt.AlignRight) self.setLayout(self.SingleCheckBoxLayout) self.setFixedHeight(70) self.setFlat(True) # options for i in options: self.add_item(i) if default is not None: index = self.combobox.findText(default) if index != -1: self.combobox.setCurrentIndex(index) if slot is not None: self.combobox.activated.connect(slot)
def __init__(self, parent=None): super(EditView, self).__init__(parent) self._layout = QBoxLayout(QBoxLayout.LeftToRight) self.setLayout(self._layout) self.setWindowTitle('Edit configuration') self._configurationTreeWidget = TreeWidget() self._configurationTreeWidget.setColumnCount(2) self._configurationTreeWidget.setHeaderLabels(["Configuration name", "Print amount"]) self._materialTreeWidget = TreeWidget() self._materialTreeWidget.setColumnCount(2) self._materialTreeWidget.setHeaderLabels(["Material name", "Print amount"]) self._initialize_material_model() self._currentConfiguration = None # type: Configuration config_widget = QWidget() self._configLayout = QBoxLayout(QBoxLayout.TopToBottom) self._nameField = QLineEdit() self._nameField.setEnabled(False) name_form_layout = QFormLayout() name_form_layout.addRow('Name:', self._nameField) self._configLayout.addLayout(name_form_layout) self._configLayout.addWidget(QLabel('List of configurations')) self._configLayout.addWidget(self._configurationTreeWidget) config_widget.setLayout(self._configLayout) self._saveButton = QPushButton("Save") material_widget = QWidget() self._materialLayout = QBoxLayout(QBoxLayout.TopToBottom) self._materialLayout.addWidget(self._saveButton) self._materialLayout.addWidget(QLabel('List of materials')) self._materialLayout.addWidget(self._materialTreeWidget) material_widget.setLayout(self._materialLayout) self._layout.addWidget(config_widget) self._layout.addWidget(material_widget) # add event listener for selection change self._configurationTreeWidget.setEditTriggers(self._configurationTreeWidget.NoEditTriggers) self._materialTreeWidget.setEditTriggers(self._materialTreeWidget.NoEditTriggers) self._configurationTreeWidget.itemDoubleClicked.connect(self._check_edit_configuration) self._materialTreeWidget.itemDoubleClicked.connect(self._check_edit_material) self._materialTreeWidget.expanded.connect(self._resize_columns) self._materialTreeWidget.collapsed.connect(self._resize_columns) self._materialTreeWidget.itemChecked.connect(self._on_toggle) self._saveButton.clicked.connect(self._save)
def __init__(self, orientation, title, parent=None): super(SlidersGroup, self).__init__(title, parent) self.slider = QSlider(orientation) self.slider.setFocusPolicy(Qt.StrongFocus) self.slider.setTickPosition(QSlider.TicksBothSides) self.slider.setTickInterval(10) self.slider.setSingleStep(1) self.scrollBar = QScrollBar(orientation) self.scrollBar.setFocusPolicy(Qt.StrongFocus) self.dial = QDial() self.dial.setFocusPolicy(Qt.StrongFocus) self.slider.valueChanged.connect(self.scrollBar.setValue) self.scrollBar.valueChanged.connect(self.dial.setValue) self.dial.valueChanged.connect(self.slider.setValue) self.dial.valueChanged.connect(self.valueChanged) if orientation == Qt.Horizontal: direction = QBoxLayout.TopToBottom else: direction = QBoxLayout.LeftToRight slidersLayout = QBoxLayout(direction) slidersLayout.addWidget(self.slider) slidersLayout.addWidget(self.scrollBar) slidersLayout.addWidget(self.dial) self.setLayout(slidersLayout)
def __init__(self): super(Window, self).__init__() global current_state current_state = dict(screen_data) self.createControls() self.createCommandBox() self.brightnessSliders = SlidersGroup(self.commandBox) self.stackedWidget = QStackedWidget() self.stackedWidget.addWidget(self.brightnessSliders) layout = QBoxLayout(QBoxLayout.TopToBottom) layout.addWidget(self.stackedWidget) layout.addWidget(self.commandBoxGroup) layout.addWidget(self.controlsGroup) self.setLayout(layout) self.setWindowTitle("Brightness editor") self.resize(850, 500) command = "# get display names and brightness values\n" + \ get_brightness_command + "\n" + \ "# results (formatted): " + str(screen_data) if primary != None: command += " primary: " + screen_data[primary][0] self.commandBox.document().setPlainText(command)
def __init__(self, *args, **kwargs): # set parent super().__init__(kwargs['main_window']) self.setModal(True) self.show() self.setWindowTitle("New Course") self.setFixedSize(400, 150) # main widget #main_widget = QWidget() main_layout = QBoxLayout(QBoxLayout.TopToBottom) # form widget form_widget = QWidget() form_layout = QFormLayout() form_layout.setFormAlignment(QtCore.Qt.AlignLeft) new_course_label = QLabel("Course Name:") new_course_entry = CustomLineEdit(default_entry="<Enter course name>") new_course_entry.setFixedWidth(230) form_layout.addRow(new_course_label, new_course_entry) form_widget.setLayout(form_layout) # action buttons action_widget = QWidget() add_course_button = QPushButton("Add Course") cancel_button = QPushButton("Cancel") action_layout = QBoxLayout(QBoxLayout.LeftToRight) action_layout.addWidget(cancel_button) action_layout.addWidget(add_course_button) action_widget.setLayout(action_layout) action_widget.setTabOrder(add_course_button, cancel_button) # add widgets main_layout.addWidget(form_widget) main_layout.addWidget(action_widget) self.setLayout(main_layout) new_course_entry.setFocus() new_course_entry.selectAll()
class GroupOfImages(QGroupBox): def __init__(self): super(GroupOfImages, self).__init__() self.GroupOfImagesLayout = QBoxLayout(QBoxLayout.TopToBottom) GroupOfImages.setFixedHeight(self, 300) GroupOfImages.setFixedWidth(self, 300) self.height = 300 def addImage(self, image): self.GroupOfImagesLayout.addWidget(image) self.height += 300 GroupOfImages.setFixedHeight(self, self.height + 300) self.setLayout(self.GroupOfImagesLayout) def removeImage(self, image): self.GroupOfImagesLayout.removeWidget(image) self.setLayout(self.GroupOfImagesLayout) def refreshView(self): self.setLayout(self.GroupOfImagesLayout)
def install_layout_for_widget(widget, orientation=None, margins=None, spacing=None): """ Installs a layout to widget, if it does not have it already. :param widget: target widget :param orientation: Qt.Vertical (default) / Qt.Horizontal :param margins: layout margins = (11, 11, 11, 11) from Qt docs, style dependent :param spacing: spacing between items in layout :return: None """ if widget.layout() is not None: logger.debug('Widget {0} already has a layout, skipping'.format(widget.windowTitle())) return # already has a layout direction = QBoxLayout.TopToBottom if orientation == Qt.Horizontal: direction = QBoxLayout.LeftToRight l = QBoxLayout(direction) if margins is not None: l.setContentsMargins(margins[0], margins[1], margins[2], margins[3]) if spacing is not None: l.setSpacing(spacing) widget.setLayout(l)
def __init__(self, message, title): super(ErrorMessage, self).__init__() self.message = message # self.setWindowTitle(title) self.setStyleSheet(style.style_loader.stylesheet) self.label = QLabel(str(self.message), self) self.label_widget = QWidget(self) label_layout = QBoxLayout(QBoxLayout.LeftToRight) label_layout.addWidget(self.label) self.label_widget.setLayout(label_layout) self.submit_btn = QPushButton('OK', self) self.submit_btn.clicked.connect(self.submit) self.submit_btn_widget = QWidget(self) submit_btn_layout = QBoxLayout(QBoxLayout.LeftToRight) submit_btn_layout.addWidget(self.submit_btn) self.submit_btn_widget.setLayout(submit_btn_layout) layout = QFormLayout() layout.addRow(self.label_widget) layout.addRow(self.submit_btn_widget) self.setLayout(layout) self.show() self.setFixedHeight(self.height()) self.setFixedWidth(self.width()) self.close()
def __init__(self): super(AddPlayerWidget, self).__init__() self.users = {} # self.setWindowTitle('Add Player') self.setStyleSheet(style.style_loader.stylesheet) self.label = QLabel('Enter Name:', self) self.label_widget = QWidget(self) label_layout = QBoxLayout(QBoxLayout.LeftToRight) label_layout.addWidget(self.label) self.label_widget.setLayout(label_layout) self.user_box = QComboBox(self) self.user_box.setFixedWidth(210) self.user_box.setFixedHeight(50) self.user_box_widget = QWidget(self) user_box_layout = QBoxLayout(QBoxLayout.LeftToRight) user_box_layout.addWidget(self.user_box) self.user_box_widget.setLayout(user_box_layout) self.submit_btn = QPushButton('Add Player', self) self.submit_btn.clicked.connect(self.submit) self.submit_btn_widget = QWidget(self) submit_btn_layout = QBoxLayout(QBoxLayout.LeftToRight) submit_btn_layout.addWidget(self.submit_btn) self.submit_btn_widget.setLayout(submit_btn_layout) layout = QFormLayout() layout.addRow(self.label_widget) layout.addRow(self.user_box_widget) layout.addRow(self.submit_btn_widget) self.setLayout(layout) self.show() self.setFixedHeight(self.height()) self.setFixedWidth(self.width()) self.close()
def __init__(self, parent=None): super(ConfigurationView, self).__init__(parent) self._layout = QBoxLayout(QBoxLayout.TopToBottom) self.setLayout(self._layout) self._editView = EditView(parent) # initialize list view self._listView = QListView() self._configuration_model = self._get_config_model() self._listView.setModel(self._configuration_model) # initialize detail view self._detailView = QWidget() self._detailLayout = QBoxLayout(QBoxLayout.TopToBottom) self._detailView.setLayout(self._detailLayout) self._detailPanels = {} self._currentDetailPanel = None self._currentConfiguration = None # type: Configuration self._config_wide_print_amounts = {} self._recalculateEffectivePrintAmounts = False # add widgets to layout self._layout.addWidget(QLabel("List of Configurations")) self._layout.addWidget(self._listView) self._layout.addWidget(self._detailView) self._create_detail_view() # hide detail view on start self._detailView.hide() # selected configs map self._selected_configs = {} self._selected_counter = 0 # add event listener for selection change self._listView.clicked.connect(self._on_selection_change) self._listView.selectionModel().currentChanged.connect(self._on_selection_change)
def __init__(self, name, lower, upper, step_size, default, slot, float_flag): super(SliderWidget, self).__init__() self.valueChanged = pyqtSignal() self.internal_steps = abs(upper - lower) / step_size print("Default " + str(default)) def to_internal_coordinate(value): return (self.internal_steps / (upper - lower)) * (value - lower) def to_external_coordinate(value): return lower + (value * (upper - lower)) / self.internal_steps # Slider itself self.slider = \ Slider(0, self.internal_steps, 1, to_internal_coordinate(default)).slider # Textfield if float_flag: self.textfield = \ DoubleTextfield(lower, upper, step_size, default).textfield else: self.textfield = \ IntegerTextfield(lower, upper, step_size, default).textfield # Label self.label = QLabel() self.label.setText(name + ": ") # Connect Textfield with Slider def textfield_value_changed(value): self.slider.setValue(to_internal_coordinate(value)) def slider_value_changed(value): self.textfield.setValue(to_external_coordinate(value)) self.textfield.valueChanged.connect(textfield_value_changed) self.slider.valueChanged.connect(slider_value_changed) self.SingleSlidersLayout = QBoxLayout(QBoxLayout.LeftToRight) self.SingleSlidersLayout.addWidget(self.label) self.SingleSlidersLayout.addWidget(self.slider) self.SingleSlidersLayout.addWidget(self.textfield) self.setLayout(self.SingleSlidersLayout) self.setFixedHeight(70) self.setFlat(True) self.textfield.valueChanged.connect(lambda : slot(self.textfield.value()))
def __init__(self, parent): super(PairingsWidget, self).__init__(parent) self.parent = parent view.notifier.observers.append(self) self.header_label = QLabel('Pairings') self.header_widget = QWidget(self) header_layout = QBoxLayout(QBoxLayout.TopToBottom) header_layout.addWidget(self.header_label) self.header_widget.setLayout(header_layout) self.pairings_list = QTableWidget(style.style_loader.TABLE_INITIAL_LENGTH, 2, self) self.pairings_list.setFixedHeight(300) self.pairings_list.setFixedWidth(400) self.pairings_list.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.pairings_list.verticalHeader().setSectionResizeMode(QHeaderView.Fixed) self.pairings_list_widget = QWidget(self) pairings_list_layout = QBoxLayout(QBoxLayout.LeftToRight) pairings_list_layout.addWidget(self.pairings_list) self.pairings_list_widget.setLayout(pairings_list_layout) self.report_btn = QPushButton('Report Results', self) self.report_btn.clicked.connect(parent.show_report_result_widget) self.report_btn_widget = QWidget(self) report_btn_layout = QBoxLayout(QBoxLayout.LeftToRight) report_btn_layout.addWidget(self.report_btn) self.report_btn_widget.setLayout(report_btn_layout) layout = QFormLayout() layout.addRow(self.header_widget) layout.addRow(self.pairings_list_widget) layout.addRow(self.report_btn_widget) self.setLayout(layout) self.update()
def __init__(self, parent=None): super(PrintView, self).__init__(parent) self._layout = QBoxLayout(QBoxLayout.TopToBottom) self.setLayout(self._layout) # initialize config = Config() self._printerSelection = QComboBox() self._printerSelection.addItems(config.get("Data", "printers").split(",")) self._printerSelection.setEditable(True) self._printButton = QPushButton("Print") form_layout = QFormLayout() form_layout.addRow("Printer:", self._printerSelection) self._layout.addLayout(form_layout) self._layout.addWidget(self._printButton) self._model = None # type: QTreeWidget # initialize event listener self._printButton.clicked.connect(self._print)
def __init__(self, name): super(ComboBoxWidget, self).__init__() self.valueChanged = pyqtSignal() # ComboBox itself self.combobox = QtWidgets.QComboBox() self.combobox.orientationCombo = PyQt5.QtWidgets.QComboBox() self.combobox.setFixedWidth(220) # Label self.label = PyQt5.QtWidgets.QLabel() self.label.setText(name + ": ") self.SingleCheckBoxLayout = QBoxLayout(QBoxLayout.LeftToRight) self.SingleCheckBoxLayout.addWidget(self.label) self.SingleCheckBoxLayout.addWidget(self.combobox, Qt.AlignRight) self.setLayout(self.SingleCheckBoxLayout) self.setFixedHeight(50) self.setFlat(True)
def __init__(self, commandBox, parent=None): super(SlidersGroup, self).__init__("", parent) self.slidersLayout = QBoxLayout(QBoxLayout.LeftToRight) self.commandBox = commandBox self.sliders = [] # self.spinBoxes = [] self.labels = [] if len(screen_data) == 1: self.slidersLayout.addStretch() for i, (name, value) in enumerate(screen_data): self.createBrightnessCtrl(name, value, i) if len(screen_data) > 1: self.createBrightnessCtrl("All", 100, None) self.sliders[-1].valueChanged.connect(self.setAllValues) self.setLayout(self.slidersLayout) self.refreshCurrentValues()
def __init__(self, name, lower, upper, step_size, default, float_flag): super(SliderWidget, self).__init__() self.internal_steps = abs(upper - lower) / step_size def ExternalCoordinate2InternalCoordinate(self, value): return (self.internal_steps / (upper - lower)) * (value - lower) def InternalCoordinate2ExternalCoordinate(self, value): return lower + (value * (upper - lower)) / self.internal_steps # Slider itself self.slider = Slider(0, self.internal_steps, 1, ExternalCoordinate2InternalCoordinate(self, default)).slider # Textfield if float_flag: self.textfield = DoubleTextfield(lower, upper, step_size, default).textfield else: self.textfield = IntegerTextfield(lower, upper, step_size, default).textfield # Label self.label = QLabel() self.label.setText(name + ": ") # Connect Textfield with Slider def textfield_value_changed(value): self.slider.setValue(ExternalCoordinate2InternalCoordinate(self, value)) def slider_value_changed(value): self.textfield.setValue(InternalCoordinate2ExternalCoordinate(self, value)) self.textfield.valueChanged.connect(textfield_value_changed) self.slider.valueChanged.connect(slider_value_changed) self.SingleSlidersLayout = QBoxLayout(QBoxLayout.LeftToRight) self.SingleSlidersLayout.addWidget(self.label) self.SingleSlidersLayout.addWidget(self.slider) self.SingleSlidersLayout.addWidget(self.textfield) self.setLayout(self.SingleSlidersLayout)
def createBrightnessCtrl(self, name, value, i): sl = QSlider(Qt.Vertical) sl.setFocusPolicy(Qt.StrongFocus) sl.setTickPosition(QSlider.TicksBothSides) sl.setTickInterval(10) sl.setSingleStep(1) sl.setMinimum(5) sl.setMaximum(100) sl.setValue(value) sb = QSpinBox() sb.setRange(5, 100) sb.setSingleStep(10) sb.setValue(value) sl.valueChanged.connect(sb.setValue) sb.valueChanged.connect(sl.setValue) if i != None: sl.valueChanged.connect(self.setValuePartial(i)) sb.valueChanged.connect(self.setValuePartial(i)) boxLayout = QBoxLayout(QBoxLayout.LeftToRight) lbl = QLabel(name) boxLayout.addWidget(lbl) boxLayout.addWidget(sb) boxLayout.addWidget(sl) self.slidersLayout.addLayout(boxLayout) # stretch is between (label, spinner, slider) groups if i != None: self.slidersLayout.addStretch() self.sliders.append(sl) # self.spinBoxes.append(sl) self.labels.append(lbl)
def __init__(self, parent=None): super(AddConfigurationDialog, self).__init__(parent) self._layout = QBoxLayout(QBoxLayout.TopToBottom) self.setLayout(self._layout) self.setWindowTitle('Add configuration') self._nameField = QLineEdit() name_form_layout = QFormLayout() name_form_layout.addRow('Name:', self._nameField) self._layout.addLayout(name_form_layout) self._layout.addWidget(QLabel("You won't be able to change this name later.")) self._cancelButton = QPushButton("Cancel") self._saveButton = QPushButton("Create") button_layout = QBoxLayout(QBoxLayout.LeftToRight) button_layout.addWidget(self._cancelButton) button_layout.addWidget(self._saveButton) self._layout.addLayout(button_layout) self._configuration = None self._cancelButton.clicked.connect(self.reject) self._saveButton.clicked.connect(self._saved)
class AddConfigurationDialog(QDialog): def __init__(self, parent=None): super(AddConfigurationDialog, self).__init__(parent) self._layout = QBoxLayout(QBoxLayout.TopToBottom) self.setLayout(self._layout) self.setWindowTitle('Add configuration') self._nameField = QLineEdit() name_form_layout = QFormLayout() name_form_layout.addRow('Name:', self._nameField) self._layout.addLayout(name_form_layout) self._layout.addWidget(QLabel("You won't be able to change this name later.")) self._cancelButton = QPushButton("Cancel") self._saveButton = QPushButton("Create") button_layout = QBoxLayout(QBoxLayout.LeftToRight) button_layout.addWidget(self._cancelButton) button_layout.addWidget(self._saveButton) self._layout.addLayout(button_layout) self._configuration = None self._cancelButton.clicked.connect(self.reject) self._saveButton.clicked.connect(self._saved) def _saved(self): name = self._nameField.text() self._configuration = Configuration(name) data = DataStorage() data.add_configuration(self._configuration) data.persist() self.accept() def get_configuration(self): """ Returns the created configuration if called after executing the dialog or None otherwise. :rtype: Configuration """ return self._configuration
def __init__(self, orientation=None, delay=200, parent=None): """ Constructor @param orientation orientation of the sidebar widget (North, East, South, West) @param delay value for the expand/shrink delay in milliseconds (integer) @param parent parent widget (QWidget) """ super(E5SideBar, self).__init__(parent) self.__tabBar = QTabBar() self.__tabBar.setDrawBase(True) self.__tabBar.setShape(QTabBar.RoundedNorth) self.__tabBar.setUsesScrollButtons(True) self.__tabBar.setDrawBase(False) self.__stackedWidget = QStackedWidget(self) self.__stackedWidget.setContentsMargins(0, 0, 0, 0) self.__autoHideButton = QToolButton() self.__autoHideButton.setCheckable(True) self.__autoHideButton.setIcon( UI.PixmapCache.getIcon("autoHideOff.png")) self.__autoHideButton.setChecked(True) self.__autoHideButton.setToolTip( self.tr("Deselect to activate automatic collapsing")) self.barLayout = QBoxLayout(QBoxLayout.LeftToRight) self.barLayout.setContentsMargins(0, 0, 0, 0) self.layout = QBoxLayout(QBoxLayout.TopToBottom) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) self.barLayout.addWidget(self.__autoHideButton) self.barLayout.addWidget(self.__tabBar) self.layout.addLayout(self.barLayout) self.layout.addWidget(self.__stackedWidget) self.setLayout(self.layout) # initialize the delay timer self.__actionMethod = None self.__delayTimer = QTimer(self) self.__delayTimer.setSingleShot(True) self.__delayTimer.setInterval(delay) self.__delayTimer.timeout.connect(self.__delayedAction) self.__minimized = False self.__minSize = 0 self.__maxSize = 0 self.__bigSize = QSize() self.splitter = None self.splitterSizes = [] self.__hasFocus = False # flag storing if this widget or any child has the focus self.__autoHide = False self.__tabBar.installEventFilter(self) self.__orientation = E5SideBar.North if orientation is None: orientation = E5SideBar.North self.setOrientation(orientation) self.__tabBar.currentChanged[int].connect( self.__stackedWidget.setCurrentIndex) e5App().focusChanged[QWidget, QWidget].connect(self.__appFocusChanged) self.__autoHideButton.toggled[bool].connect(self.__autoHideToggled)
def __init__(self, parent): super(RoundManagerWidget, self).__init__(parent) self.parent = parent self.sort_order = 'by_name' view.notifier.observers.append(self) timer = QTimer(self) timer.timeout.connect(self.update) timer.start() self.header_label = QLabel('Round') self.header_widget = QWidget(self) header_layout = QBoxLayout(QBoxLayout.LeftToRight) header_layout.addWidget(self.header_label) self.header_widget.setLayout(header_layout) self.submit_btn = QPushButton(self) self.submit_btn.clicked.connect(self.submit) self.submit_btn_widget = QWidget(self) submit_btn_layout = QBoxLayout(QBoxLayout.LeftToRight) submit_btn_layout.addWidget(self.submit_btn) self.submit_btn_widget.setLayout(submit_btn_layout) self.round_info = QLabel() self.round_info.setAlignment(Qt.AlignCenter) self.timer_display = QLabel() self.timer_display.setAlignment(Qt.AlignCenter) self.info_widget = QWidget(self) info_layout = QBoxLayout(QBoxLayout.LeftToRight) info_layout.addWidget(self.round_info) info_layout.addWidget(self.timer_display) self.info_widget.setLayout(info_layout) self.error = None layout = QFormLayout() layout.addRow(self.header_widget) layout.addRow(self.submit_btn_widget) layout.addRow(self.info_widget) self.setLayout(layout) self.update()
def load_settings_widgets_from_pipeline_groupbox(self, position): """ Extracts all widgets from a single algorithm and returns a QBoxLayout Args: alg: the alg instance we extract from Returns: a QBoxLayout containing all widgets for this particular alg. """ alg = self.pipeline.executed_cats[position].active_algorithm print("alg " + str(alg)) print("cat " + str(self.pipeline.executed_cats[position])) empty_flag = True groupOfSliders = QGroupBox() sp = QSizePolicy() sp.setVerticalPolicy(QSizePolicy.Preferred) # groupOfSliders.setSizePolicy(sp) groupOfSliderssLayout = QBoxLayout(QBoxLayout.TopToBottom) groupOfSliderssLayout.setContentsMargins(0, -0, -0, 0) groupOfSliderssLayout.setAlignment(Qt.AlignTop) groupOfSliderssLayout.setSpacing(0) print("Build Slider @ "+ str(position)) # create integer sliders for slider in alg.integer_sliders: empty_flag = False print("slider.value " + str(slider.value)) print("slider " + str(slider)) #print(alg.get_name() + ": add slider (int).") groupOfSliderssLayout.addWidget( SliderWidget(slider.name, slider.lower, slider.upper, slider.step_size, slider.value, slider.set_value, False)) # create float sliders for slider in alg.float_sliders: empty_flag = False #print(alg.get_name() + ": add slider (float).") groupOfSliderssLayout.addWidget( SliderWidget(slider.name, slider.lower, slider.upper, slider.step_size, slider.value, slider.set_value, True), 0, Qt.AlignTop) # create checkboxes for checkbox in alg.checkboxes: empty_flag = False #print(alg.get_name() + ": add checkbox.") groupOfSliderssLayout.addWidget(CheckBoxWidget(checkbox.name, checkbox.value, checkbox.set_value), 0, Qt.AlignTop) # create dropdowns for combobox in alg.drop_downs: empty_flag = False #print(alg.get_name() + ": add combobox.") groupOfSliderssLayout.addWidget( ComboBoxWidget(combobox.name, combobox.options, combobox.set_value, combobox.value), 0, Qt.AlignTop) if empty_flag: label = QLabel() label.setText("This algorithm has no Settings.") groupOfSliderssLayout.addWidget(label, 0, Qt.AlignHCenter) groupOfSliders.setLayout(groupOfSliderssLayout) return groupOfSliders
class SliderWidget(QGroupBox): """ This is a combined widget for a slider in the GUI. It contains several input fields and a slider itself. By setting the constructor value, the complete widget is connected in itself. The name will be displayed in front of the widget. lower and upper refer to the sliders range, step_size tells the distance of each step and default is the preset value in the GUI. The float_flag determines whether the slider should represent float values or not. Set float_flag to true if you want to store float values. With self.valueChanged on can connect a pyqt slot with the float slider pyqtSignal. A SliderWidget is built by a Slider, a QLabel and either a DoubleTextfield or an IntegerTextfield. """ def __init__(self, name, lower, upper, step_size, default, slot, float_flag): super(SliderWidget, self).__init__() self.valueChanged = pyqtSignal() self.internal_steps = abs(upper - lower) / step_size print("Default " + str(default)) def to_internal_coordinate(value): return (self.internal_steps / (upper - lower)) * (value - lower) def to_external_coordinate(value): return lower + (value * (upper - lower)) / self.internal_steps # Slider itself self.slider = \ Slider(0, self.internal_steps, 1, to_internal_coordinate(default)).slider # Textfield if float_flag: self.textfield = \ DoubleTextfield(lower, upper, step_size, default).textfield else: self.textfield = \ IntegerTextfield(lower, upper, step_size, default).textfield # Label self.label = QLabel() self.label.setText(name + ": ") # Connect Textfield with Slider def textfield_value_changed(value): self.slider.setValue(to_internal_coordinate(value)) def slider_value_changed(value): self.textfield.setValue(to_external_coordinate(value)) self.textfield.valueChanged.connect(textfield_value_changed) self.slider.valueChanged.connect(slider_value_changed) self.SingleSlidersLayout = QBoxLayout(QBoxLayout.LeftToRight) self.SingleSlidersLayout.addWidget(self.label) self.SingleSlidersLayout.addWidget(self.slider) self.SingleSlidersLayout.addWidget(self.textfield) self.setLayout(self.SingleSlidersLayout) self.setFixedHeight(70) self.setFlat(True) self.textfield.valueChanged.connect(lambda : slot(self.textfield.value()))