我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtWidgets.QHBoxLayout()。
def __init__(self, parent=None): super(SearchLineEdit, self).__init__() self.setObjectName("SearchLine") self.parent = parent self.setMinimumSize(218, 20) with open('QSS/searchLine.qss', 'r') as f: self.setStyleSheet(f.read()) self.button = QPushButton(self) self.button.setMaximumSize(13, 13) self.button.setCursor(QCursor(Qt.PointingHandCursor)) self.setTextMargins(3, 0, 19, 0) self.spaceItem = QSpacerItem(150, 10, QSizePolicy.Expanding) self.mainLayout = QHBoxLayout() self.mainLayout.addSpacerItem(self.spaceItem) # self.mainLayout.addStretch(1) self.mainLayout.addWidget(self.button) self.mainLayout.addSpacing(10) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.mainLayout)
def setupUi(self, MiniBrowserWidget): MiniBrowserWidget.setObjectName("MiniBrowserWidget") MiniBrowserWidget.resize(665, 483) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(MiniBrowserWidget.sizePolicy().hasHeightForWidth()) MiniBrowserWidget.setSizePolicy(sizePolicy) self.horizontalLayout = QtWidgets.QHBoxLayout(MiniBrowserWidget) self.horizontalLayout.setObjectName("horizontalLayout") self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.browser = QtWebKitWidgets.QWebView(MiniBrowserWidget) self.browser.setUrl(QtCore.QUrl("http://yandex.ru/")) self.browser.setObjectName("browser") self.verticalLayout.addWidget(self.browser) self.horizontalLayout.addLayout(self.verticalLayout) self.retranslateUi(MiniBrowserWidget) QtCore.QMetaObject.connectSlotsByName(MiniBrowserWidget)
def __init__(self, parent): super().__init__(parent) self._list = QtWidgets.QListWidget(self) self._list.itemDoubleClicked.connect(self._playItem) vlayout = QtWidgets.QVBoxLayout() vlayout.addWidget(self._list, stretch=1) btn = QtWidgets.QPushButton('', self) btn.setIcon(QtGui.QIcon('../icons/add.svg')) btn.setFlat(True) btn.clicked.connect(self._browse) hlayout = QtWidgets.QHBoxLayout() hlayout.addWidget(btn) hlayout.addStretch(1) vlayout.addLayout(hlayout) self.setLayout(vlayout)
def initUI(self): self.tf = 'PlotTextFile.txt' self.createTopLeftGroupBox() self.createTopRightGroupBox() self.createBottomLeftGroupBox() self.createBottomRightGroupBox() topLayout = QHBoxLayout() topLayout.addWidget(self.topLeftGroupBox) topLayout.addWidget(self.topRightGroupBox) bottomLayout = QHBoxLayout() bottomLayout.addWidget(self.bottomLeftGroupBox) bottomLayout.addWidget(self.bottomRightGroupBox) mainLayout = QVBoxLayout() mainLayout.addLayout(topLayout) mainLayout.addLayout(bottomLayout) mainLayout.addStretch(1) self.setLayout(mainLayout) self.show()
def createTopLeftGroupBox(self): self.topLeftGroupBox = QGroupBox("Temperature Sensor") tempLabel = QLabel('Temperature: ') self.tempValLabel = QLabel('NULL') plotButton = QPushButton("Show Plot") plotButton.clicked.connect(self.tempPlot) saveDataButton = QPushButton('Save Data File') saveDataButton.clicked.connect(self.savefile) vbox1 = QVBoxLayout() vbox1.addWidget(tempLabel) vbox1.addWidget(self.tempValLabel) vbox2 = QVBoxLayout() vbox2.addWidget(plotButton) vbox2.addWidget(saveDataButton) layout = QHBoxLayout() layout.addLayout(vbox1) layout.addLayout(vbox2) layout.addStretch(1) self.topLeftGroupBox.setLayout(layout)
def createTopRightGroupBox(self): self.topRightGroupBox = QGroupBox('Heater') heatLabel = QLabel('Target Temperature(C):') heatEntry = QLineEdit() heatEntry.textChanged[str].connect(self.tempOnChanged) heatEntry.setText('41') self.heatButton = QPushButton('Heater ON') self.heatButton.clicked.connect(self.heaterPower) hbox1 = QHBoxLayout() hbox1.addWidget(heatLabel) hbox1.addWidget(heatEntry) hbox2 = QHBoxLayout() hbox2.addWidget(self.heatButton) layout = QVBoxLayout() layout.addLayout(hbox1) layout.addLayout(hbox2) layout.addStretch(1) self.topRightGroupBox.setLayout(layout)
def initUI(self): self.tf = 'PlotTextFile.txt' self.statusbar = 'Ready' self.createTopGroupBox() self.createMidGroupBox() self.createBottomLeftGroupBox() self.createBottomRightGroupBox() topLayout = QVBoxLayout() topLayout.addWidget(self.topGroupBox) topLayout.addWidget(self.midGroupBox) bottomLayout = QHBoxLayout() bottomLayout.addWidget(self.bottomLeftGroupBox) bottomLayout.addWidget(self.bottomRightGroupBox) mainLayout = QVBoxLayout() mainLayout.addLayout(topLayout) mainLayout.addLayout(bottomLayout) mainLayout.addStretch(1) self.setLayout(mainLayout) self.show()
def layout(self): """ Lay out the dialog. """ main_layout = QW.QVBoxLayout(self) test_layout = QW.QHBoxLayout() button_layout = QW.QVBoxLayout() self._fitter_select = QW.QListWidget() self._fitter_select.setSelectionMode(QW.QAbstractItemView.ExtendedSelection) for k,v in self._fit_snapshot_dict.items(): self._fitter_select.addItem(k) self._fitter_select.setFixedSize(150, 100) ftest_button = QW.QPushButton("Perform AIC Test", self) ftest_button.clicked.connect(self.perform_test) add_fit_button = QW.QPushButton("Append New Fit", self) add_fit_button.clicked.connect(self.add_fitter) self._data_out = QW.QTextEdit() self._data_out.setReadOnly(True) self._data_out.setMinimumWidth(400) # add buttons to layout button_layout.addWidget(ftest_button) button_layout.addWidget(add_fit_button) # add widgets to layout test_layout.addWidget(self._fitter_select) test_layout.addLayout(button_layout) main_layout.addLayout(test_layout) main_layout.addWidget(self._data_out) self.setWindowTitle('AIC Test')
def _layout(self): """ Create layout. """ self._main_layout = QW.QHBoxLayout(self) if self._input_type is bool: self._select_widget = QW.QCheckBox() self._select_widget.stateChanged.connect(self._bool_handler) self._select_widget.setChecked(self._initial_value) elif self._input_type is str: self._select_widget = QW.QLineEdit() self._select_widget.editingFinished.connect(self._str_handler) self._select_widget.setText(self._initial_value) elif self._input_type is int: self._select_widget = QW.QLineEdit() self._select_widget.editingFinished.connect(self._int_handler) self._select_widget.setText(str(self._initial_value)) else: self._select_widget = QW.QLineEdit() self._select_widget.editingFinished.connect(self._general_handler) self._select_widget.setText(str(self._initial_value)) self._main_layout.addWidget(self._select_widget)
def __init__(self, text="Loading..."): super(MessageBox, self).__init__() self.setWindowTitle("Messages") self.setLayout(QtWidgets.QHBoxLayout()) self._layout = self.layout() self._gif = QtWidgets.QLabel() movie = QtGui.QMovie("loading.gif") self._gif.setMovie(movie) movie.start() self._layout.addWidget(self._gif) self._message = QtWidgets.QLabel() self._message.setText(text) self._layout.addWidget(self._message) self.setObjectName('Message_Window')
def __init__(self): super(ProjectsWidget, self).__init__() self.projects_list = ProjectListWidget() # Buttons self.new_project_button = QtWidgets.QPushButton(QtGui.QIcon(icons.add), 'New') self.copy_project_button = QtWidgets.QPushButton(QtGui.QIcon(icons.copy), 'Copy current') self.delete_project_button = QtWidgets.QPushButton(QtGui.QIcon(icons.delete), 'Delete current') # Layout self.h_layout = QtWidgets.QHBoxLayout() self.h_layout.addWidget(header('Current Project:')) self.h_layout.addWidget(self.projects_list) self.h_layout.addWidget(self.new_project_button) self.h_layout.addWidget(self.copy_project_button) self.h_layout.addWidget(self.delete_project_button) self.setLayout(self.h_layout) self.setSizePolicy(QtWidgets.QSizePolicy( QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum) ) self.connect_signals()
def __init__(self, parent=None): super().__init__(parent) self.path_edit = QtWidgets.QLineEdit() self.registerField('dirpath*', self.path_edit) self.browse_button = QtWidgets.QPushButton('Browse') self.browse_button.clicked.connect(self.get_directory) layout = QtWidgets.QVBoxLayout() layout.addWidget(QtWidgets.QLabel( 'Choose location of existing ecospold2 directory:')) layout.addWidget(self.path_edit) browse_lay = QtWidgets.QHBoxLayout() browse_lay.addWidget(self.browse_button) browse_lay.addStretch(1) layout.addLayout(browse_lay) self.setLayout(layout)
def __init__(self, parent=None): super().__init__(parent) self.wizard = self.parent() self.complete = False self.description_label = QtWidgets.QLabel('Login to the ecoinvent homepage:') self.username_edit = QtWidgets.QLineEdit() self.username_edit.setPlaceholderText('ecoinvent username') self.password_edit = QtWidgets.QLineEdit() self.password_edit.setPlaceholderText('ecoinvent password'), self.password_edit.setEchoMode(QtWidgets.QLineEdit.Password) self.login_button = QtWidgets.QPushButton('login') self.login_button.clicked.connect(self.login) self.login_button.setCheckable(True) self.password_edit.returnPressed.connect(self.login_button.click) self.success_label = QtWidgets.QLabel('') layout = QtWidgets.QVBoxLayout() layout.addWidget(self.description_label) layout.addWidget(self.username_edit) layout.addWidget(self.password_edit) hlay = QtWidgets.QHBoxLayout() hlay.addWidget(self.login_button) hlay.addStretch(1) layout.addLayout(hlay) layout.addWidget(self.success_label) self.setLayout(layout)
def __init__(self, item, parent=None): super().__init__(parent) self._item = item self._values = [] layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) model = self._item.model() model.dataChanged.connect(self._on_data_changed) append_button = QtWidgets.QPushButton() append_button.setText('+') append_button.setMaximumWidth(32) append_button.clicked.connect(self._on_append_button_clicked) self.layout().addWidget(append_button) self.update_widgets()
def init_ui(self): # Creating a label self.progressLabel = QLabel('Progress Bar:', self) # Creating a progress bar and setting the value limits self.progressBar = QProgressBar(self) self.progressBar.setMaximum(100) self.progressBar.setMinimum(0) # Creating a Horizontal Layout to add all the widgets self.hboxLayout = QHBoxLayout(self) # Adding the widgets self.hboxLayout.addWidget(self.progressLabel) self.hboxLayout.addWidget(self.progressBar) # Setting the hBoxLayout as the main layout self.setLayout(self.hboxLayout) self.setWindowTitle('Dialog with Progressbar') self.show()
def add_classes_frame(self): self.vbox.setStretch(self.vbox.count()-1, 0) hbox = QtWidgets.QHBoxLayout() self.vbox.addLayout(hbox) self.class_line = QtWidgets.QGridLayout() hbox.addLayout(self.class_line) hbox.addStretch(1) self.class_num = QtWidgets.QButtonGroup() self.refresh_classes() hbox = QtWidgets.QHBoxLayout() self.vbox.addLayout(hbox) button = QtWidgets.QPushButton('Show', self) button.clicked.connect(self.show_selected_class) hbox.addWidget(button) button = QtWidgets.QPushButton('See all', self) button.clicked.connect(self.show_all_classes) hbox.addWidget(button) button = QtWidgets.QPushButton('Refresh', self) button.clicked.connect(self.refresh_classes) hbox.addWidget(button) hbox.addStretch(1) self.vbox.addStretch(1)
def __init__(self): QtWidgets.QWidget.__init__(self) uic.loadUi("window.ui", self) self.scene = QtWidgets.QGraphicsScene(0, 0, 511, 511) self.mainview.setScene(self.scene) self.image = QImage(511, 511, QImage.Format_ARGB32_Premultiplied) self.pen = QPen() self.color_line = QColor(Qt.black) self.color_bground = QColor(Qt.white) self.draw_once.clicked.connect(lambda: draw_once(self)) self.clean_all.clicked.connect(lambda: clear_all(self)) self.btn_bground.clicked.connect(lambda: get_color_bground(self)) self.btn_line.clicked.connect(lambda: get_color_line(self)) self.draw_centr.clicked.connect(lambda: draw_centr(self)) layout = QtWidgets.QHBoxLayout() layout.addWidget(self.what) layout.addWidget(self.other) self.setLayout(layout) self.circle.setChecked(True) self.canon.setChecked(True) #self.circle.toggled.connect(lambda : change_text(self))
def __init__(self, parent=None): super(Adventure, self).__init__(parent) # # Top-half of the # self.image_panel = QtWidgets.QLabel() self.image_panel.setAlignment(QtCore.Qt.AlignCenter) self.image = QtGui.QPixmap("image.jpg") self.image_panel.setPixmap(self.image) self.text_panel = QtWidgets.QTextEdit() self.text_panel.setReadOnly(True) self.text_panel.setTextBackgroundColor(QtGui.QColor("blue")) self.text_panel.setHtml("""<h1>Hello, World!</h1> <p>You are in a spacious ballroom with the sound of music playing all around you.</p> """) self.data_panel = QtWidgets.QTextEdit() self.data_panel.setReadOnly(True) self.input = QtWidgets.QLineEdit() layout = QtWidgets.QVBoxLayout() layout.addWidget(self.image_panel, 1) hlayout = QtWidgets.QHBoxLayout() hlayout.addWidget(self.text_panel, 3) hlayout.addWidget(self.data_panel, 1) layout.addLayout(hlayout, 1) layout.addWidget(self.input) self.setLayout(layout) self.setWindowTitle("Westpark Adventure")
def createHorizontalLayout(self): self.horizontalGroupBox = QGroupBox("What is your favorite color?") layout = QHBoxLayout() buttonBlue = QPushButton('Blue', self) buttonBlue.clicked.connect(self.on_click) layout.addWidget(buttonBlue) buttonRed = QPushButton('Red', self) buttonRed.clicked.connect(self.on_click) layout.addWidget(buttonRed) buttonGreen = QPushButton('Green', self) buttonGreen.clicked.connect(self.on_click) layout.addWidget(buttonGreen) self.horizontalGroupBox.setLayout(layout)
def window(): app = QtWidgets.QApplication(sys.argv) w = QtWidgets.QWidget() b = QtWidgets.QPushButton('Push Me') l = QtWidgets.QLabel('Look at me') h_box = QtWidgets.QHBoxLayout() h_box.addStretch() h_box.addWidget(l) h_box.addStretch() v_box = QtWidgets.QVBoxLayout() v_box.addWidget(b) v_box.addLayout(h_box) w.setLayout(v_box) w.setWindowTitle('PyQt5 Lesson 4') w.show() sys.exit(app.exec_())
def init_ui(self): v_layout = QVBoxLayout() h_layout = QHBoxLayout() h_layout.addWidget(self.clr_btn) h_layout.addWidget(self.sav_btn) h_layout.addWidget(self.opn_btn) v_layout.addWidget(self.text) v_layout.addLayout(h_layout) self.sav_btn.clicked.connect(self.save_text) self.clr_btn.clicked.connect(self.clear_text) self.opn_btn.clicked.connect(self.open_text) self.setLayout(v_layout) self.setWindowTitle("notepad") self.show()
def init_ui(self): self.b = QtWidgets.QPushButton('Push Me') self.l = QtWidgets.QLabel('I have not been clicked yet') h_box = QtWidgets.QHBoxLayout() h_box.addStretch() h_box.addWidget(self.l) h_box.addStretch() v_box = QtWidgets.QVBoxLayout() v_box.addWidget(self.b) v_box.addLayout(h_box) self.setLayout(v_box) self.setWindowTitle('PyQt5 Lesson 5') self.b.clicked.connect(self.btn_click) self.show()
def init_ui(self): v_layout = QVBoxLayout() h_layout = QHBoxLayout() h_layout.addWidget(self.clr_btn) h_layout.addWidget(self.sav_btn) h_layout.addWidget(self.opn_btn) v_layout.addWidget(self.text) v_layout.addLayout(h_layout) self.sav_btn.clicked.connect(self.save_text) self.clr_btn.clicked.connect(self.clear_text) self.opn_btn.clicked.connect(self.open_text) self.setLayout(v_layout) self.setWindowTitle('PyQt5 TextEdit') self.show()
def init_ui(self): v_layout = QVBoxLayout() h_layout = QHBoxLayout() h_layout.addWidget(self.clr_btn) h_layout.addWidget(self.sav_btn) h_layout.addWidget(self.opn_btn) v_layout.addWidget(self.text) v_layout.addLayout(h_layout) self.sav_btn.clicked.connect(self.save_text) self.clr_btn.clicked.connect(self.clear_text) self.opn_btn.clicked.connect(self.open_text) self.setLayout(v_layout) #self.setWindowTitle("notepad") #self.setWindowIcon(QIcon('notepad.png')) self.show()
def __init__(self, icon: str, parent=None, f=Qt.Dialog | Qt.FramelessWindowHint): super(Notification, self).__init__(parent, f) self.parent = parent self.theme = self.parent.theme self.setObjectName('notification') self.setContentsMargins(10, 10, 10, 10) self.shown.connect(lambda: QTimer.singleShot(self.duration * 1000, self.fadeOut)) self.setWindowModality(Qt.ApplicationModal) self.setMinimumWidth(550) self._title, self._message = '', '' self.buttons = [] self.msgLabel = QLabel(self._message, self) self.msgLabel.setWordWrap(True) logo_label = QLabel('<img src="{}" width="82" />'.format(icon), self) logo_label.setFixedSize(82, 82) self.left_layout = QVBoxLayout() self.left_layout.addWidget(logo_label) layout = QHBoxLayout() layout.addStretch(1) layout.addLayout(self.left_layout) layout.addSpacing(10) layout.addWidget(self.msgLabel, Qt.AlignVCenter) layout.addStretch(1) self.setLayout(layout)
def __init__(self, parent=None): QtWidgets.QFrame.__init__(self, parent) # No title bar, but keep the frame # self.setWindowFlags(QtCore.Qt.CustomizeWindowHint) # Set position of the frame self.screen = QtWidgets.QDesktopWidget().screenGeometry() # Set geometry self.setGeometry(self.screen.width()/8, 50, 1600, 900) self.setMinimumSize(0, 0) # Set Widgets self.sideWindow = SideFrame(self) self.mainWindow = MainFrame(self) # Set Layout self.appLayout = QtWidgets.QHBoxLayout() self.appLayout.addWidget(self.sideWindow, 2) self.appLayout.addWidget(self.mainWindow, 8) # Add layout self.appLayout.setContentsMargins(0, 0, 0, 0) self.appLayout.setSpacing(0) self.setLayout(self.appLayout) self.setWindowTitle("Bayesian Adaptive Trial Simulator") # Close the application
def __init__(self, text, unit = None, minimum = None, maximum = None, parent = None): """ Initialization of the CfgSpinBox class (used for int values). @param text: text string associated with the SpinBox @param minimum: min value (int) @param minimum: max value (int) """ QWidget.__init__(self, parent) self.spinbox = QSpinBox(parent) if unit is not None: self.setUnit(unit) self.setSpec({'minimum': minimum, 'maximum': maximum, 'comment': ''}) self.label = QLabel(text, parent) self.layout = QHBoxLayout(parent); self.spinbox.setMinimumWidth(200) #Provide better alignment with other items self.layout.addWidget(self.label) self.layout.addStretch() self.layout.addWidget(self.spinbox) self.setLayout(self.layout)
def __init__(self, text, items_list = None, default_item = None, parent = None): """ Initialization of the CfgComboBox class (drop-down menu). @param text: text string associated with the combobox @param items_list: string list containing all the available options @param default_item: string containing the default selected item """ QWidget.__init__(self, parent) self.combobox = QComboBox(parent) if isinstance(items_list, (list, tuple)): self.setSpec({'string_list': items_list, 'comment': ''}) if default_item is not None: self.setValue(default_item) self.label = QLabel(text, parent) self.layout = QHBoxLayout(parent); self.combobox.setMinimumWidth(200) #Provide better alignment with other items self.layout.addWidget(self.label) self.layout.addStretch() self.layout.addWidget(self.combobox) self.setLayout(self.layout)
def __init__(self, id_, name, value): super().__init__() self.id_ = id_ self.name = name self.value = value self.win = None self.label = QtWidgets.QLabel(name) self.input = QtWidgets.QDoubleSpinBox() self.input.setSuffix("€") self.input.setMaximum(999.99) self.input.setLocale(QtCore.QLocale('English')) self.label.setBuddy(self.input) self._build() self.layout = QtWidgets.QHBoxLayout(self) self.layout.addWidget(self.label) self.layout.addWidget(self.input)
def __init__(self): super(MemNavWidget, self).__init__() self.expr_entry = QtWidgets.QLineEdit() self.esize_entry = QtWidgets.QLineEdit() hbox1 = QtWidgets.QHBoxLayout() hbox1.setContentsMargins(2, 2, 2, 2) hbox1.setSpacing(4) hbox1.addWidget(self.expr_entry) hbox1.addWidget(self.esize_entry) self.setLayout(hbox1) self.expr_entry.returnPressed.connect(self.emitUserChangedSignal) self.esize_entry.returnPressed.connect(self.emitUserChangedSignal)
def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(188, 48) Dialog.setWindowTitle("") self.horizontalLayout = QtWidgets.QHBoxLayout(Dialog) self.horizontalLayout.setObjectName("horizontalLayout") self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) self.buttonBox.setCenterButtons(True) self.buttonBox.setObjectName("buttonBox") self.verticalLayout.addWidget(self.buttonBox) self.horizontalLayout.addLayout(self.verticalLayout) self.retranslateUi(Dialog) self.buttonBox.accepted.connect(Dialog.accept) self.buttonBox.rejected.connect(Dialog.reject) QtCore.QMetaObject.connectSlotsByName(Dialog)
def __init__(self): QWidget.__init__(self) self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint) self.setFixedSize(400, 70) main_vbox = QVBoxLayout() hbox= QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) self.progress = gpvdm_progress() self.spinner=spinner() hbox.addWidget(self.progress, 0) hbox.addWidget(self.spinner, 0) w=QWidget() w.setLayout(hbox) main_vbox.addWidget(w,0) self.label=QLabel() self.label.setText(_("Running")+"...") main_vbox.addWidget(self.label) self.setLayout(main_vbox)
def __init__(self,file_box=False): QWidget.__init__(self) self.hbox=QHBoxLayout() self.edit=QLineEdit() self.button=QPushButton() self.button.setFixedSize(25, 25) self.button.setText("...") self.hbox.addWidget(self.edit) self.hbox.addWidget(self.button) self.hbox.setContentsMargins(0, 0, 0, 0) self.edit.setStyleSheet("QLineEdit { border: none }"); if file_box==True: self.button.clicked.connect(self.callback_button_click) self.setLayout(self.hbox)
def init_ui(self): self._mainWidget = QWidget() self._drawWidget = QWidget() self._btns_widget = QWidget() self._layout_buttons = QVBoxLayout() self._layout_draw = QHBoxLayout() self._drawWidget.setLayout(self._layout_draw) self._vLayout = QVBoxLayout() self._vLayout.setSpacing(2) self.setCentralWidget(self._mainWidget) self._mainWidget.setLayout(self._vLayout) self.configure_buttons() self._tesseractWidget = TesseractWidget() self._svs = ScreenViewScene() self._layout_draw.addWidget(self._btns_widget) self._layout_draw.addWidget(self._svs) self._vLayout.addWidget(self._drawWidget) self._vLayout.addWidget(self._tesseractWidget) self._svs.signal_send_image.connect(self.setImage) self._tesseractWidget.signal_send_text.connect(self._svs.switch_to_text)
def main(): application = QtWidgets.QApplication([]) window = QtWidgets.QWidget() layout_numbers = QtWidgets.QVBoxLayout(window) result = QtWidgets.QTextEdit() layout_numbers.addWidget(result) # Numbers from 0 to 9, Numeros de 0 a 9 for number in range(10): button = QtWidgets.QPushButton(str(number)) button.clicked.connect(lambda _, number=number: result.insertPlainText(str(number))) layout_numbers.addWidget(button) # Math Operators, Operadores Matematicos operators = QtWidgets.QWidget() layout_operators = QtWidgets.QHBoxLayout(operators) for operator in ("*", "/", "+", "-", "//"): button = QtWidgets.QPushButton(str(operator)) button.clicked.connect(lambda _, operator=operator: result.insertPlainText(str(operator))) layout_operators.addWidget(button) layout_numbers.addWidget(operators) # Solve the user input, Resolver lo ingresado por el usuario solve = QtWidgets.QPushButton("EVAL", window) solve.clicked.connect(lambda _, maths=result: result.setPlainText(str(eval(maths.toPlainText())))) layout_numbers.addWidget(solve) window.show() exit(application.exec_())
def __init__(self, parent=None): super().__init__() self.parent = parent self.setVisible(False) self.setStyleSheet("QDialog {background-color: rgba(22, 22, 22, 150); border-color: rgba(22, 22, 22, 150);" \ "border-width: 1px; border-style outset; border-radius: 10px; color:white; font-weight:bold;}") layout = QHBoxLayout() self.setLayout(layout) label = QLabel() label.setStyleSheet("QLabel {color:white;}") label.setText("Kodlama:") layout.addWidget(label) self.combobox = QComboBox() self.combobox.addItems(["ISO 8859-9", "UTF-8"]) self.combobox.setStyleSheet("QComboBox {background-color: rgba(22, 22, 22, 150); border-color: rgba(22, 22, 22, 150);" \ " color:white; font-weight:bold;}") self.combobox.setCurrentText(settings().value("Subtitle/codec")) layout.addWidget(self.combobox) self.combobox.currentTextChanged.connect(self.textCodecChange)
def setupUi(self, window): window.setObjectName("window") window.resize(380, 477) window.setModal(True) self.verticalLayout = QtWidgets.QVBoxLayout(window) self.verticalLayout.setObjectName("verticalLayout") self.txt_list = QtWidgets.QTextEdit(window) self.txt_list.setMinimumSize(QtCore.QSize(183, 0)) self.txt_list.setAcceptRichText(False) self.txt_list.setObjectName("txt_list") self.verticalLayout.addWidget(self.txt_list) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setContentsMargins(-1, -1, -1, 10) self.horizontalLayout.setObjectName("horizontalLayout") self.btn_cancel = QtWidgets.QPushButton(window) self.btn_cancel.setAutoDefault(False) self.btn_cancel.setObjectName("btn_cancel") self.horizontalLayout.addWidget(self.btn_cancel) spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.btn_ok = QtWidgets.QPushButton(window) self.btn_ok.setAutoDefault(True) self.btn_ok.setObjectName("btn_ok") self.horizontalLayout.addWidget(self.btn_ok) self.verticalLayout.addLayout(self.horizontalLayout) self.retranslateUi(window) QtCore.QMetaObject.connectSlotsByName(window)
def __init__(self, parent): super().__init__() self.parent = parent self.setFixedSize(300, 150) self.setLayout(QVBoxLayout()) hlayout = QHBoxLayout() self.layout().addLayout(hlayout) label = QLabel() label.setText(self.tr("Mount Point:")) hlayout.addWidget(label) self.combobox = QComboBox() hlayout.addWidget(self.combobox) self.dialbutton = QDialogButtonBox() self.dialbutton.setStandardButtons(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) self.layout().addWidget(self.dialbutton) self.dialbutton.button(QDialogButtonBox.Ok).setText(self.tr("Ok")) self.dialbutton.button(QDialogButtonBox.Cancel).setText(self.tr("Cancel")) self.dialbutton.accepted.connect(self.editAccept) self.dialbutton.rejected.connect(self.close)
def setupUi(self, Window): Window.setObjectName("Window") Window.resize(640, 480) self.verticalLayout = QtWidgets.QVBoxLayout(Window) self.verticalLayout.setObjectName("verticalLayout") self.webView = QtWebKitWidgets.QWebView(Window) self.webView.setUrl(QtCore.QUrl("http://webkit.org/")) self.webView.setObjectName("webView") self.verticalLayout.addWidget(self.webView) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.formLayout = QtWidgets.QFormLayout() self.formLayout.setFieldGrowthPolicy(QtWidgets.QFormLayout.ExpandingFieldsGrow) self.formLayout.setObjectName("formLayout") self.elementLabel = QtWidgets.QLabel(Window) self.elementLabel.setObjectName("elementLabel") self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.elementLabel) self.elementLineEdit = QtWidgets.QLineEdit(Window) self.elementLineEdit.setObjectName("elementLineEdit") self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.elementLineEdit) self.horizontalLayout.addLayout(self.formLayout) self.highlightButton = QtWidgets.QPushButton(Window) self.highlightButton.setObjectName("highlightButton") self.horizontalLayout.addWidget(self.highlightButton) self.verticalLayout.addLayout(self.horizontalLayout) self.elementLabel.setBuddy(self.elementLineEdit) self.retranslateUi(Window) QtCore.QMetaObject.connectSlotsByName(Window)
def __init__(self, *args): QtWidgets.QFrame.__init__(self, *args) self.setFrameStyle(QtWidgets.QFrame.StyledPanel | QtWidgets.QFrame.Sunken) self.edit = self.PlainTextEdit() self.number_bar = self.NumberBar(self.edit) hbox = QtWidgets.QHBoxLayout(self) hbox.setSpacing(0) hbox.setContentsMargins(0,0,0,0) # setMargin hbox.addWidget(self.number_bar) hbox.addWidget(self.edit) self.edit.blockCountChanged.connect(self.number_bar.adjustWidth) self.edit.updateRequest.connect(self.number_bar.updateContents)
def quickLayout(self, type, ui_name=""): the_layout = '' if type in ("form", "QFormLayout"): the_layout = QtWidgets.QFormLayout() the_layout.setLabelAlignment(QtCore.Qt.AlignLeft) the_layout.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow) elif type in ("grid", "QGridLayout"): the_layout = QtWidgets.QGridLayout() elif type in ("hbox", "QHBoxLayout"): the_layout = QtWidgets.QHBoxLayout() the_layout.setAlignment(QtCore.Qt.AlignTop) else: the_layout = QtWidgets.QVBoxLayout() the_layout.setAlignment(QtCore.Qt.AlignTop) if ui_name != "": self.uiList[ui_name] = the_layout return the_layout
def __init__(self, playbin, parent): super().__init__(parent) self._playbin = playbin self._state = self.STATE_IDLE self._started = None self._updater = None self._slider = QtWidgets.QSlider(QtCore.Qt.Horizontal) self._elapsed = QtWidgets.QLabel('00:00:00') self._remaining = QtWidgets.QLabel('00:00:00') self._slider.setMinimum(0) layout = QtWidgets.QHBoxLayout() layout.setContentsMargins(2, 2, 2, 2) layout.addWidget(self._elapsed) layout.addWidget(self._slider, stretch=1) layout.addWidget(self._remaining) self.setLayout(layout) self._slider.sliderPressed.connect(self._startDragging) self._slider.sliderMoved.connect(self._drag) self._slider.sliderReleased.connect(self._stopDragging) self._updater = asyncio.get_event_loop().create_task(self._poll())
def __init__(self, api, main_window): super().__init__(main_window) model = StylesModel(api) selection_model = QtCore.QItemSelectionModel(model) self._style_list = StyleList(api, model, selection_model, self) self._style_editor = StyleEditor(model, selection_model, self) if api.video.path: self._preview_box = StylePreview(api, selection_model, self) else: self._preview_box = None self._style_editor.setEnabled(False) layout = QtWidgets.QHBoxLayout(self) layout.addWidget(self._style_list) layout.addWidget(self._style_editor) if self._preview_box: layout.addWidget(self._preview_box)
def __init__(self, api, parent=None): super().__init__(parent) self.text_edit = TextEdit( api, 'editor', self, tabChangesFocus=True) self.note_edit = TextEdit( api, 'notes', self, tabChangesFocus=True, placeholderText='Notes') self.text_edit.highlighter = \ SpellCheckHighlighter(api, self.text_edit.document()) layout = QtWidgets.QHBoxLayout(self) layout.setSpacing(4) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.text_edit) layout.addWidget(self.note_edit)
def initUI(self): self.tf = 'PlotTextFile.txt' self.statusbar = 'Ready' self.createTopGroupBox() self.createMidTopGroupBox() self.createMidBottomGroupBox() self.createBottomLeftGroupBox() self.createBottomRightGroupBox() topLayout = QVBoxLayout() topLayout.addWidget(self.topGroupBox) topLayout.addWidget(self.midTopGroupBox) topLayout.addWidget(self.midBottomGroupBox) bottomLayout = QHBoxLayout() bottomLayout.addWidget(self.bottomLeftGroupBox) bottomLayout.addWidget(self.bottomRightGroupBox) mainLayout = QVBoxLayout() mainLayout.addLayout(topLayout) mainLayout.addLayout(bottomLayout) mainLayout.addStretch(1) self.setLayout(mainLayout) self.show()
def createTopGroupBox(self): self.topGroupBox = QGroupBox('Integration Time') self.it2_4ms = QRadioButton() self.it2_4ms.setText('2.4ms') self.it2_4ms.toggled.connect(lambda: self.itstate(self.it2_4ms)) self.it24ms = QRadioButton() self.it24ms.setText('24ms') self.it24ms.toggled.connect(lambda: self.itstate(self.it24ms)) self.it50ms = QRadioButton() self.it50ms.setText('50ms') self.it50ms.toggled.connect(lambda: self.itstate(self.it50ms)) self.it101ms = QRadioButton() self.it101ms.setText('101ms') self.it101ms.toggled.connect(lambda: self.itstate(self.it101ms)) self.it154ms = QRadioButton() self.it154ms.setText('154ms') self.it154ms.toggled.connect(lambda: self.itstate(self.it154ms)) self.it700ms = QRadioButton() self.it700ms.setText('700ms') self.it700ms.toggled.connect(lambda: self.itstate(self.it700ms)) self.it2_4ms.setChecked(True) layout = QHBoxLayout() layout.addWidget(self.it2_4ms) layout.addWidget(self.it24ms) layout.addWidget(self.it50ms) layout.addWidget(self.it101ms) layout.addWidget(self.it154ms) layout.addWidget(self.it700ms) layout.addStretch(1) self.topGroupBox.setLayout(layout)
def createMidGroupBox(self): self.midGroupBox = QGroupBox('Gain') self.gain1 = QRadioButton() self.gain1.setText('1X') self.gain1.toggled.connect(lambda: self.gnstate(self.gain1)) self.gain4 = QRadioButton() self.gain4.setText('4X') self.gain4.toggled.connect(lambda: self.gnstate(self.gain4)) self.gain16 = QRadioButton() self.gain16.setText('16X') self.gain16.toggled.connect(lambda: self.gnstate(self.gain16)) self.gain60 = QRadioButton() self.gain60.setText('60X') self.gain60.toggled.connect(lambda: self.gnstate(self.gain60)) self.gain1.setChecked(True) layout = QHBoxLayout() layout.addWidget(self.gain1) layout.addWidget(self.gain4) layout.addWidget(self.gain16) layout.addWidget(self.gain60) layout.addStretch(1) self.midGroupBox.setLayout(layout)
def createBottomRightGroupBox(self): self.bottomRightGroupBox = QGroupBox('Sensor Data') self.intensityLbl = QLabel('Not Taken') layout = QHBoxLayout() layout.addWidget(self.intensityLbl) layout.addStretch(1) self.bottomRightGroupBox.setLayout(layout)
def setupUi(self, Form): Form.setObjectName("Form") Form.resize(224, 117) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth()) Form.setSizePolicy(sizePolicy) self.verticalLayout = QtWidgets.QVBoxLayout(Form) self.verticalLayout.setSpacing(1) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.translateLabel = QtWidgets.QLabel(Form) self.translateLabel.setObjectName("translateLabel") self.verticalLayout.addWidget(self.translateLabel) self.rotateLabel = QtWidgets.QLabel(Form) self.rotateLabel.setObjectName("rotateLabel") self.verticalLayout.addWidget(self.rotateLabel) self.scaleLabel = QtWidgets.QLabel(Form) self.scaleLabel.setObjectName("scaleLabel") self.verticalLayout.addWidget(self.scaleLabel) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.mirrorImageBtn = QtWidgets.QPushButton(Form) self.mirrorImageBtn.setToolTip("") self.mirrorImageBtn.setObjectName("mirrorImageBtn") self.horizontalLayout.addWidget(self.mirrorImageBtn) self.reflectImageBtn = QtWidgets.QPushButton(Form) self.reflectImageBtn.setObjectName("reflectImageBtn") self.horizontalLayout.addWidget(self.reflectImageBtn) self.verticalLayout.addLayout(self.horizontalLayout) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)