本文整理匯總了Python中qtpy.QtWidgets.QMainWindow.setCentralWidget方法的典型用法代碼示例。如果您正苦於以下問題:Python QMainWindow.setCentralWidget方法的具體用法?Python QMainWindow.setCentralWidget怎麽用?Python QMainWindow.setCentralWidget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qtpy.QtWidgets.QMainWindow
的用法示例。
在下文中一共展示了QMainWindow.setCentralWidget方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_window
# 需要導入模塊: from qtpy.QtWidgets import QMainWindow [as 別名]
# 或者: from qtpy.QtWidgets.QMainWindow import setCentralWidget [as 別名]
def create_window():
# Create app and widgets
app = QApplication(sys.argv)
win = QMainWindow()
main_area = QWidget()
button_area = QWidget()
scroll_area = QScrollArea()
button = QPushButton("Start Video")
btn_grab = QPushButton("Grab Frame")
# Create layouts
vbox = QVBoxLayout()
hbox = QHBoxLayout()
# Fill Layouts
vbox.addWidget(scroll_area)
vbox.addWidget(button_area)
hbox.addStretch()
hbox.addWidget(button)
hbox.addWidget(btn_grab)
# Assign layouts to widgets
main_area.setLayout(vbox)
button_area.setLayout(hbox)
scroll_area.setLayout(QVBoxLayout())
# Attach some child widgets directly
win.setCentralWidget(main_area)
return app, win, button, btn_grab, scroll_area
示例2: create_figure_window
# 需要導入模塊: from qtpy.QtWidgets import QMainWindow [as 別名]
# 或者: from qtpy.QtWidgets.QMainWindow import setCentralWidget [as 別名]
def create_figure_window(title=''):
"""Creates a figure in a Qt window. Returns the tuple (window, mplfigure)"""
win = QMainWindow()
mplfig = MPLFigure()
win.setCentralWidget(mplfig.canvas)
win.setWindowTitle(title)
return win, mplfig
示例3: MyPowerSupply
# 需要導入模塊: from qtpy.QtWidgets import QMainWindow [as 別名]
# 或者: from qtpy.QtWidgets.QMainWindow import setCentralWidget [as 別名]
from instrumental.gui import UDoubleSpinBox
class MyPowerSupply(Instrument):
voltage = ManualFacet(type=float, units='volts')
current = ManualFacet(type=float, units='amps')
if __name__ == '__main__':
ps = MyPowerSupply()
ps.observe('voltage', print)
app = QApplication(sys.argv)
win = QMainWindow()
w = QWidget(win)
win.setCentralWidget(w)
fbox = QFormLayout()
box1 = ps.facets.voltage.create_widget()
fbox.addRow('Voltage', box1)
box2 = ps.facets.current.create_widget()
fbox.addRow('Current', box2)
def set_box(event):
box1.setUValue(event.new)
ps.observe('voltage', set_box)
def f():
ps.voltage = '12 V'
#box2.uValueChanged.connect(f)
示例4: __init__
# 需要導入模塊: from qtpy.QtWidgets import QMainWindow [as 別名]
# 或者: from qtpy.QtWidgets.QMainWindow import setCentralWidget [as 別名]
#
# def __init__(self, holdIt, value):
# QThread.__init__(self)
# self.holdIt = holdIt
# self.value = value
#
# def run(self):
# t = time.time()
# time.sleep(2)
# self.holdIt.update_duration = time.time() - t
# print "update finished", self.value
if __name__ == '__main__':
app = QApplication(sys.argv)
m = QMainWindow()
w = QWidget()
m.setCentralWidget(w)
vlayout = QVBoxLayout(w)
s_log = LogaritmicSliderSpinBox(m, slider_steps=100)
s_lin = SliderSpinBox(m, slider_steps=100)
s_pol = PolynomialSliderSpinBox(m, 2, slider_steps=100, spinbox_steps=1000)
vlayout.addWidget(s_lin)
vlayout.addWidget(s_log)
vlayout.addWidget(s_pol)
#m.setCentralWidget(s)
s_log.set_range((0.001, 1000))
m.show()
sys.exit(app.exec_())
示例5: PlotWindow
# 需要導入模塊: from qtpy.QtWidgets import QMainWindow [as 別名]
# 或者: from qtpy.QtWidgets.QMainWindow import setCentralWidget [as 別名]
class PlotWindow(QMdiSubWindow):
"""
Displayed plotting subwindow available in the ``QMdiArea``.
"""
window_removed = Signal()
color_changed = Signal(PlotDataItem, QColor)
width_changed = Signal(int)
def __init__(self, model, *args, **kwargs):
super(PlotWindow, self).__init__(*args, **kwargs)
# Hide the icon in the title bar
self.setWindowIcon(qta.icon('fa.circle', opacity=0))
# The central widget of the sub window will be a main window so that it
# can support having tab bars
self._central_widget = QMainWindow()
self.setWidget(self._central_widget)
loadUi(os.path.join(os.path.dirname(__file__), "ui", "plot_window.ui"),
self._central_widget)
# The central widget of the main window widget will be the plot
self._model = model
self._current_item_index = None
self._plot_widget = PlotWidget(model=self._model)
self._plot_widget.plotItem.setMenuEnabled(False)
self._central_widget.setCentralWidget(self._plot_widget)
# Setup action group for interaction modes
mode_group = QActionGroup(self.tool_bar)
mode_group.addAction(self._central_widget.pan_mode_action)
self._central_widget.pan_mode_action.setChecked(True)
mode_group.addAction(self._central_widget.zoom_mode_action)
def _toggle_mode(state):
view_state = self.plot_widget.plotItem.getViewBox().state.copy()
view_state.update({'mouseMode': pg.ViewBox.RectMode
if state else pg.ViewBox.PanMode})
self.plot_widget.plotItem.getViewBox().setState(view_state)
# Setup plot settings options menu
self.plot_settings_button = self.tool_bar.widgetForAction(
self._central_widget.plot_settings_action)
self.plot_settings_button.setPopupMode(QToolButton.InstantPopup)
self.plot_settings_menu = QMenu(self.plot_settings_button)
self.plot_settings_button.setMenu(self.plot_settings_menu)
self.color_change_action = QAction("Line Color")
self.plot_settings_menu.addAction(self.color_change_action)
self.line_width_menu = QMenu("Line Widths")
self.plot_settings_menu.addMenu(self.line_width_menu)
# Setup the line width plot setting options
for i in range(1, 4):
act = QAction(str(i), self.line_width_menu)
self.line_width_menu.addAction(act)
act.triggered.connect(lambda *args, size=i:
self._on_change_width(size))
# Setup connections
self._central_widget.pan_mode_action.triggered.connect(
lambda: _toggle_mode(False))
self._central_widget.zoom_mode_action.triggered.connect(
lambda: _toggle_mode(True))
self._central_widget.linear_region_action.triggered.connect(
self.plot_widget._on_add_linear_region)
self._central_widget.remove_region_action.triggered.connect(
self.plot_widget._on_remove_linear_region)
self.color_change_action.triggered.connect(
self._on_change_color)
self._central_widget.export_plot_action.triggered.connect(
self._on_export_plot)
self._central_widget.reset_view_action.triggered.connect(
lambda: self._on_reset_view())
@property
def tool_bar(self):
"""
Return the tool bar for the embedded plot widget.
"""
return self._central_widget.tool_bar
@property
def current_item(self):
"""
The currently selected plot data item.
"""
if self._current_item_index is not None:
return self.proxy_model.item_from_index(self._current_item_index)
@property
def plot_widget(self):
"""
Return the embedded plot widget
"""
return self._plot_widget
#.........這裏部分代碼省略.........