本文整理汇总了Python中qtpy.QtWidgets.QGridLayout.addWidget方法的典型用法代码示例。如果您正苦于以下问题:Python QGridLayout.addWidget方法的具体用法?Python QGridLayout.addWidget怎么用?Python QGridLayout.addWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QGridLayout
的用法示例。
在下文中一共展示了QGridLayout.addWidget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_file_combobox
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def create_file_combobox(self, text, choices, option, default=NoDefault,
tip=None, restart=False, filters=None,
adjust_to_contents=False,
default_line_edit=False):
"""choices: couples (name, key)"""
combobox = FileComboBox(self, adjust_to_contents=adjust_to_contents,
default_line_edit=default_line_edit)
combobox.restart_required = restart
combobox.label_text = text
edit = combobox.lineEdit()
edit.label_text = text
edit.restart_required = restart
self.lineedits[edit] = (option, default)
if tip is not None:
combobox.setToolTip(tip)
combobox.addItems(choices)
msg = _('Invalid file path')
self.validate_data[edit] = (osp.isfile, msg)
browse_btn = QPushButton(ima.icon('FileIcon'), '', self)
browse_btn.setToolTip(_("Select file"))
browse_btn.clicked.connect(lambda: self.select_file(edit, filters))
layout = QGridLayout()
layout.addWidget(combobox, 0, 0, 0, 9)
layout.addWidget(browse_btn, 0, 10)
layout.setContentsMargins(0, 0, 0, 0)
widget = QWidget(self)
widget.combobox = combobox
widget.browse_btn = browse_btn
widget.setLayout(layout)
return widget
示例2: setup_gui
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def setup_gui(self):
"""Setup the main layout of the widget."""
layout = QGridLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.canvas, 0, 1)
layout.addLayout(self.setup_toolbar(), 0, 3, 2, 1)
layout.setColumnStretch(0, 100)
layout.setColumnStretch(2, 100)
layout.setRowStretch(1, 100)
示例3: __init__
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def __init__(self, parent):
SpyderPluginWidget.__init__(self, parent)
# Widgets
self.stack = QStackedWidget(self)
self.shellwidgets = {}
# Layout
layout = QGridLayout(self)
layout.addWidget(self.stack)
# Initialize plugin
self.initialize_plugin()
示例4: __init__
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def __init__(self, parent=None):
QWidget.__init__(self, parent)
# Widgets, layouts and signals
self._group = QButtonGroup()
layout = QGridLayout()
layout.setSpacing(0)
## Element
for z, position in _ELEMENT_POSITIONS.items():
widget = ElementPushButton(z)
widget.setCheckable(True)
layout.addWidget(widget, *position)
self._group.addButton(widget, z)
## Labels
layout.addWidget(QLabel(''), 7, 0) # Dummy
layout.addWidget(QLabel('*'), 5, 2, Qt.AlignRight)
layout.addWidget(QLabel('*'), 8, 2, Qt.AlignRight)
layout.addWidget(QLabel('**'), 6, 2, Qt.AlignRight)
layout.addWidget(QLabel('**'), 9, 2, Qt.AlignRight)
for row in [0, 1, 2, 3, 4, 5, 6, 8, 9]:
layout.setRowStretch(row, 1)
self.setLayout(layout)
# Signals
self._group.buttonClicked.connect(self.selectionChanged)
# Default
self.setColorFunction(_category_color_function)
示例5: setupUI
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def setupUI(self, widget):
self.ui.setupUi(widget)
root_widgets = [w for w in widget.children() if w.__class__.__name__ == "QWidget"]
if len(root_widgets) == 0 or widget.layout() is not None:
self.ui_widget = self
else:
self.ui_widget = root_widgets[-1]
g = QGridLayout()
if qtpy.API=="pyqt5":
pass
else:
if isinstance(self, QtWidgetLoader):
g.setMargin(0)
g.setSpacing(0)
widget.setLayout(g)
g.addWidget(self.ui_widget)
示例6: __init__
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def __init__(self, parent=None):
super().__init__(parent)
self.settings = QSettings()
# decimal
self.decimalLabel = QLabel(self.tr("decimal:"))
self.decimalComboBox = QComboBox()
self.decimalLabel.setBuddy(self.decimalComboBox)
self.decimalComboBox.addItems([",", "."])
# separator
self.separatorLabel = QLabel(self.tr("separator:"))
self.separatorComboBox = QComboBox()
self.separatorLabel.setBuddy(self.separatorComboBox)
self.separatorComboBox.addItem("Semicolon ';'", ';')
self.separatorComboBox.addItem("Comma ','", ',')
self.separatorComboBox.addItem("Tabulator '\\t'", '\t')
self.separatorComboBox.addItem("Whitespace ' '", ' ')
# buttons
self.buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel
)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
# layout
layout = QGridLayout()
layout.addWidget(self.decimalLabel, 0, 0)
layout.addWidget(self.decimalComboBox, 0, 1)
layout.addWidget(self.separatorLabel, 1, 0)
layout.addWidget(self.separatorComboBox, 1, 1)
layout.addWidget(self.buttons, 2, 0, 1, 2)
self.setLayout(layout)
# settings
self.decimalComboBox.setCurrentIndex(
self.decimalComboBox.findText(
self.settings.value(DECIMAL_SETTING, ","))
)
self.separatorComboBox.setCurrentIndex(
self.separatorComboBox.findData(
self.settings.value(SEPARATOR_SETTING, ";"))
)
self.setWindowTitle(self.tr("record settings"))
示例7: __init__
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def __init__(self, viewer_state=None, session=None):
super(BaseCustomOptionsWidget, self).__init__()
layout = QGridLayout()
for row, (name, (prefix, viewer_cls)) in enumerate(self._widgets.items()):
widget = viewer_cls()
setattr(self, prefix + name, widget)
layout.addWidget(QLabel(name.capitalize()), row, 0)
layout.addWidget(widget, row, 1)
if len(self._widgets) > 0:
layout.setRowStretch(row + 1, 10)
self.setLayout(layout)
self.viewer_state = viewer_state
self.session = session
autoconnect_callbacks_to_qt(self.viewer_state, self)
示例8: ImageWindow
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
class ImageWindow(QMainWindow):
def __init__(self, arr, mgr):
QMainWindow.__init__(self)
self.setWindowTitle('skimage')
self.mgr = mgr
self.main_widget = QWidget()
self.layout = QGridLayout(self.main_widget)
self.setCentralWidget(self.main_widget)
self.label = ImageLabel(self, arr)
self.layout.addWidget(self.label, 0, 0)
self.layout.addLayout
self.mgr.add_window(self)
self.main_widget.show()
def closeEvent(self, event):
# Allow window to be destroyed by removing any
# references to it
self.mgr.remove_window(self)
示例9: _ask_overwrite
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def _ask_overwrite(self):
msg = QDialog()
msg.setWindowTitle('Load overwrite')
layout = QGridLayout()
layout.addWidget(QLabel('Instrument %s already exists in memory. Overwrite this?'), 0, 0, 1, -1)
buttons = [QPushButton(label) for label in ['Load and overwrite', 'Cancel Load', 'Load and rename to']]
locations = [[1, 0], [1, 1], [2, 0]]
self.overwrite_flag = 1
def overwriteCB(idx):
self.overwrite_flag = idx
msg.accept()
for idx, button in enumerate(buttons):
button.clicked.connect(lambda _, idx=idx: overwriteCB(idx))
layout.addWidget(button, locations[idx][0], locations[idx][1])
newname = QLineEdit()
newname.editingFinished.connect(lambda: overwriteCB(2))
layout.addWidget(newname, 2, 1)
msg.setLayout(layout)
msg.exec_()
newname = str(newname.text())
if not newname or newname in self.instruments:
self.errormessage('Invalid instrument name. Cancelling load.')
self.overwrite_flag = 1
return self.overwrite_flag, newname
示例10: IntelligentSlider
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
class IntelligentSlider(QWidget):
''' A slider that adds a 'name' attribute and calls a callback
with 'name' as an argument to the registerd callback.
This allows you to create large groups of sliders in a loop,
but still keep track of the individual events
It also prints a label below the slider.
The range of the slider is hardcoded from zero - 1000,
but it supports a conversion factor so you can scale the results'''
def __init__(self, name, a, b, callback):
QWidget.__init__(self)
self.name = name
self.callback = callback
self.a = a
self.b = b
self.manually_triggered = False
self.slider = QSlider()
self.slider.setRange(0, 1000)
self.slider.setValue(500)
self.slider.valueChanged.connect(self.slider_changed)
self.name_label = QLabel()
self.name_label.setText(self.name)
self.name_label.setAlignment(QtCore.Qt.AlignCenter)
self.value_label = QLabel()
self.value_label.setText('%2.2f' % (self.slider.value() * self.a
+ self.b))
self.value_label.setAlignment(QtCore.Qt.AlignCenter)
self.layout = QGridLayout(self)
self.layout.addWidget(self.name_label, 0, 0)
self.layout.addWidget(self.slider, 1, 0, QtCore.Qt.AlignHCenter)
self.layout.addWidget(self.value_label, 2, 0)
# bind this to the valueChanged signal of the slider
def slider_changed(self, val):
val = self.val()
self.value_label.setText(str(val)[:4])
if not self.manually_triggered:
self.callback(self.name, val)
def set_conv_fac(self, a, b):
self.a = a
self.b = b
def set_value(self, val):
self.manually_triggered = True
self.slider.setValue(int((val - self.b) / self.a))
self.value_label.setText('%2.2f' % val)
self.manually_triggered = False
def val(self):
return self.slider.value() * self.a + self.b
示例11: QuadHistogram
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
class QuadHistogram(QFrame):
'''A class which uses ColorHistogram to draw
the 4 histograms of an image. R, G, B, and Value.
The 4 histograms are layout out in a grid,
and can be specified horizontal or vertical,
and in which order ie. ['R', 'G', 'B', 'V']
'''
def __init__(self, img, layout='vertical', order=['R', 'G', 'B', 'V']):
QFrame.__init__(self)
r, g, b, v = histograms(img, 100)
self.r_hist = ColorHistogram(r, (255, 0, 0))
self.g_hist = ColorHistogram(g, (0, 255, 0))
self.b_hist = ColorHistogram(b, (0, 0, 255))
self.v_hist = ColorHistogram(v, (0, 0, 0))
self.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken)
self.layout = QGridLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0)
order_map = {'R': self.r_hist, 'G': self.g_hist, 'B': self.b_hist,
'V': self.v_hist}
if layout == 'vertical':
for i in range(len(order)):
self.layout.addWidget(order_map[order[i]], i, 0)
elif layout == 'horizontal':
for i in range(len(order)):
self.layout.addWidget(order_map[order[i]], 0, i)
def update_hists(self, img):
r, g, b, v = histograms(img, 100)
self.r_hist.update_hist(r, (255, 0, 0))
self.g_hist.update_hist(g, (0, 255, 0))
self.b_hist.update_hist(b, (0, 0, 255))
self.v_hist.update_hist(v, (0, 0, 0))
示例12: __init__
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def __init__(self, settings, parent=None):
super().__init__(parent)
self.settings = settings
self.serialports = []
# port
self.portLabel = QLabel(self.tr("COM Port:"))
self.portComboBox = QComboBox()
self.portLabel.setBuddy(self.portComboBox)
self.refresh_comports(self.portComboBox)
# baudrate
self.baudrateLabel = QLabel(self.tr("Baudrate:"))
self.baudrateComboBox = QComboBox()
self.baudrateLabel.setBuddy(self.baudrateComboBox)
for br in BAUDRATES:
self.baudrateComboBox.addItem(str(br), br)
# buttons
self.dlgbuttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal)
self.dlgbuttons.rejected.connect(self.reject)
self.dlgbuttons.accepted.connect(self.accept)
# layout
layout = QGridLayout()
layout.addWidget(self.portLabel, 0, 0)
layout.addWidget(self.portComboBox, 0, 1)
layout.addWidget(self.baudrateLabel, 1, 0)
layout.addWidget(self.baudrateComboBox, 1, 1)
layout.addWidget(self.dlgbuttons, 2, 0, 1, 2)
self.setLayout(layout)
self.setWindowTitle(self.tr("Serial Settings"))
# settings
defaults = {
PORT_SETTING: "",
BAUDRATE_SETTING: "115200"
}
self.tmp_settings = ConfigManager()
self.tmp_settings.set_defaults(defaults)
self.tmp_settings.set_many(
{key: self.settings.get(key) for key in defaults.keys()}
)
self.tmp_settings.add_handler(PORT_SETTING, self.portComboBox)
self.tmp_settings.add_handler(BAUDRATE_SETTING, self.baudrateComboBox)
示例13: setup_ui
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def setup_ui(self):
self.setWindowTitle("Add New Grain")
self.setWindowIcon(QIcon(RESOURCE_PATH + "icons/nakka-finocyl.gif"))
self.resize(400, 400)
controls = QGridLayout()
gb_frame = QGroupBox(self.tr("Grain Design"))
gb_frame.setLayout(controls)
self.cb_grain_type = QComboBox()
# TODO: make grain types auto propagate combobox
self.cb_grain_type.addItems([self.tr("Cylindrical (BATES)")])
controls.addWidget(QLabel(self.tr("Core Shape")), 0, 0)
controls.addWidget(self.cb_grain_type, 0, 1)
self.cb_propellant_type = QComboBox()
self.cb_propellant_type.addItems(app_context.propellant_db.propellant_names())
controls.addWidget(QLabel(self.tr("Propellant Type")), 1, 0)
controls.addWidget(self.cb_propellant_type, 1, 1)
# ok and cancel buttons
btn_ok = QPushButton(self.tr("Apply"))
btn_ok.clicked.connect(self.confirm_grain)
btn_cancel = QPushButton(self.tr("Close"))
btn_cancel.clicked.connect(self.close)
lay_btns = QHBoxLayout()
lay_btns.addWidget(btn_ok)
lay_btns.addWidget(btn_cancel)
frame_btns = QFrame()
frame_btns.setLayout(lay_btns)
# master layout
master = QVBoxLayout()
master.addWidget(gb_frame)
master.addSpacing(10)
master.addWidget(frame_btns)
self.setLayout(master)
示例14: _build_GUI
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
def _build_GUI(self, linelist, table_view):
panel_layout = QGridLayout()
panel_layout.setSizeConstraint(QLayout.SetMaximumSize)
self.setLayout(panel_layout)
# GUI cannot be completely defined in a .ui file.
# It has to be built on-the-fly here.
self.button_pane = QWidget()
loadUi(os.path.join(os.path.dirname(__file__), "ui", "linelists_panel_buttons.ui"), self.button_pane)
# internal signals do not use Hub infrastructure.
self.button_pane.create_set_button.clicked.connect(self._create_set)
self.button_pane.deselect_button.clicked.connect(table_view.clearSelection)
# header with line list metadata.
info = QTextBrowser()
info.setMaximumHeight(100)
info.setAutoFillBackground(True)
info.setStyleSheet("background-color: rgb(230,230,230);")
for comment in linelist.meta['comments']:
info.append(comment)
# populate color picker
model = self.button_pane.combo_box_color.model()
for cname in ID_COLORS:
item = QStandardItem(cname)
item.setForeground(ID_COLORS[cname])
item.setData(QColor(ID_COLORS[cname]), role=Qt.UserRole)
model.appendRow(item)
# set validators
validator = QDoubleValidator()
validator.setRange(0.05, 0.95, decimals=2)
self.button_pane.height_textbox.setValidator(validator)
validator = QDoubleValidator()
validator.setRange(-1.e5, 1.e10, decimals=4)
self.button_pane.redshift_textbox.setValidator(validator)
model = self.button_pane.combo_box_z_units.model()
for uname in ['z', 'km/s']:
item = QStandardItem(uname)
model.appendRow(item)
# put it all together
panel_layout.addWidget(info,0,0)
panel_layout.addWidget(table_view,1,0)
panel_layout.addWidget(self.button_pane,2,0)
示例15: __init__
# 需要导入模块: from qtpy.QtWidgets import QGridLayout [as 别名]
# 或者: from qtpy.QtWidgets.QGridLayout import addWidget [as 别名]
#.........这里部分代码省略.........
self.line_Inf2.setValidator(QIntValidator())
self.line_Inf3 = QLineEdit()
self.line_Inf3.setValidator(QIntValidator())
self.line_Inf4 = QLineEdit()
self.line_Inf4.setValidator(QIntValidator())
self.line_Inf5 = QLineEdit()
self.line_Inf5.setValidator(QIntValidator())
self.line_Inf6 = QLineEdit()
self.line_Inf6.setValidator(QIntValidator())
self.line_Inf7 = QLineEdit()
self.line_Inf7.setValidator(QIntValidator())
self.line_Inf8 = QLineEdit()
self.line_Inf8.setValidator(QIntValidator())
self.line_Inf9 = QLineEdit()
self.line_Inf9.setValidator(QIntValidator())
#Widget Informacion Calculada Form2 Ahorros
self.line_Sav1 = QLineEdit()
self.line_Sav1.setValidator(QIntValidator())
self.line_Sav2 = QLineEdit()
self.line_Sav2.setValidator(QIntValidator())
self.line_Sav3 = QLineEdit()
self.line_Sav3.setValidator(QIntValidator())
self.line_Sav4 = QLineEdit()
self.line_Sav4.setValidator(QIntValidator())
self.line_Sav5 = QLineEdit()
self.line_Sav5.setValidator(QIntValidator())
self.line_Sav6 = QLineEdit()
self.line_Sav6.setValidator(QIntValidator())
self.button_Calc = QPushButton('Calcular Ahorro', parent=self)
self.button_Impr = QPushButton('Imprimir', parent=self)
#Layouts
layout = QGridLayout()
layout.addWidget(self.label_Title1,0,0)
layout.addWidget(self.label_Data1,1,0)
layout.addWidget(self.line_Data1,1,1)
layout.addWidget(self.label_Title2,2,0)
layout.addWidget(self.label_Data2,3,0)
layout.addWidget(self.line_Data2,3,1)
layout.addWidget(self.label_Data5,3,2)
layout.addWidget(self.line_Data5,3,3)
layout.addWidget(self.label_Data3,4,0)
layout.addWidget(self.line_Data3,4,1)
layout.addWidget(self.label_Data6,4,2)
layout.addWidget(self.line_Data6,4,3)
layout.addWidget(self.label_Data4,5,0)
layout.addWidget(self.line_Data4,5,1)
layout.addWidget(self.label_Data7,5,2)
layout.addWidget(self.line_Data7,5,3)
layout.addWidget(self.label_Title3,6,0)
layout.addWidget(self.label_Data8,7,0)
layout.addWidget(self.line_Data8,7,1)
layout.addWidget(self.label_Data10,7,2)
layout.addWidget(self.line_Data10,7,3)
layout.addWidget(self.label_Data9,8,0)
layout.addWidget(self.line_Data9,8,1)
layout.addWidget(self.button_Calc,8,3)
layout1 = QFormLayout()
layout1.addRow("Horas por año",self.line_Inf1)
layout1.addRow("Costo de Energia por Dia",self.line_Inf2)
layout1.addRow("Costo de Energia por Año",self.line_Inf3)
layout1.addRow("Costo total de la Compra",self.line_Inf4)
layout1.addRow("Costo Total de la compra con mantenimiento",self.line_Inf5)
layout1.addRow("Costo Reemplazo Actuales Año",self.line_Inf6)
layout1.addRow("Costo Energia por Dia LED",self.line_Inf7)
layout1.addRow("Costo de Energia por Año LED",self.line_Inf8)
layout1.addRow("Costo Total de la Compra LED",self.line_Inf9)
layout2 = QFormLayout()
layout2.addRow("Ahorro Energia Anual",self.line_Sav1)
layout2.addRow("Ahorro Energia Mensual",self.line_Sav2)
layout2.addRow("Periodo Retorno Inversion en Años",self.line_Sav3)
layout2.addRow("Periodo Retorno Inversion en Meses",self.line_Sav4)
layout2.addWidget(self.button_Impr)
#Layout Horizontal Titulos del Form
self.LayoutTitle = QHBoxLayout()
self.LayoutTitle.addWidget(self.label_Titlef1)
self.LayoutTitle.addWidget(self.label_Titlef2)
### Layout HOrizontal que une los dos Form
self.LayoutForm = QHBoxLayout()
self.LayoutForm.addLayout(layout1)
self.LayoutForm.addLayout(layout2)
## LAyout Vertical Final
self.myLayout = QVBoxLayout()
self.myLayout.setMargin(20)
self.myLayout.addLayout(layout)
self.myLayout.addLayout(self.LayoutTitle)
self.myLayout.addLayout(self.LayoutForm)
self.setLayout(self.myLayout)
# Signals
self.button_Calc.clicked.connect(self.result_method)