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)
python类QHBoxLayout()的实例源码
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="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, 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)