本文整理汇总了Python中qtpy.QtWidgets.QTableView.resizeColumnsToContents方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.resizeColumnsToContents方法的具体用法?Python QTableView.resizeColumnsToContents怎么用?Python QTableView.resizeColumnsToContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.resizeColumnsToContents方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from qtpy.QtWidgets import QTableView [as 别名]
# 或者: from qtpy.QtWidgets.QTableView import resizeColumnsToContents [as 别名]
def __init__(self, plotted_lines, *args, **kwargs):
super().__init__(None, *args, **kwargs)
self.plotted_lines = plotted_lines
layout = QVBoxLayout()
layout.setSizeConstraint(QLayout.SetMaximumSize)
self.setLayout(layout)
table_model = LineListTableModel(plotted_lines)
if table_model.rowCount() > 0:
table_view = QTableView()
# disabling sorting will significantly speed up theWidget
# plot. This is because the table view must be re-built
# every time a new set of markers is drawn on the plot
# surface. Alternate approaches are worth examining. It
# remains to be seen what would be the approach users
# will favor.
table_view.setSortingEnabled(False)
proxy = SortModel(table_model.get_name())
proxy.setSourceModel(table_model)
table_view.setModel(proxy)
table_view.setSortingEnabled(True)
table_view.setSelectionMode(QAbstractItemView.NoSelection)
table_view.horizontalHeader().setStretchLastSection(True)
table_view.resizeColumnsToContents()
layout.addWidget(table_view)
示例2: _create_line_list_pane
# 需要导入模块: from qtpy.QtWidgets import QTableView [as 别名]
# 或者: from qtpy.QtWidgets.QTableView import resizeColumnsToContents [as 别名]
def _create_line_list_pane(linelist, table_model, caller):
table_view = QTableView()
# disabling sorting will significantly speed up the rendering,
# in particular of large line lists. These lists are often jumbled
# in wavelength, and consequently difficult to read and use, so
# having a sorting option is useful indeed. It remains to be seen
# what would be the approach users will favor. We might add a toggle
# that users can set/reset depending on their preferences.
table_view.setSortingEnabled(False)
sort_proxy = SortModel(table_model.get_name())
sort_proxy.setSourceModel(table_model)
table_view.setModel(sort_proxy)
table_view.setSortingEnabled(True)
table_view.horizontalHeader().setStretchLastSection(True)
# playing with these doesn't speed up the sorting, regardless of whatever
# you may read on the net.
#
# table_view.horizontalHeader().setResizeMode(QHeaderView.Fixed)
# table_view.verticalHeader().setResizeMode(QHeaderView.Fixed)
# table_view.horizontalHeader().setStretchLastSection(False)
# table_view.verticalHeader().setStretchLastSection(False)
table_view.setSelectionMode(QAbstractItemView.ExtendedSelection)
table_view.setSelectionBehavior(QAbstractItemView.SelectRows)
table_view.resizeColumnsToContents()
# this preserves the original sorting state of the list. Use zero
# to sort by wavelength on load. Doesn't seem to affect performance
# by much tough.
sort_proxy.sort(-1, Qt.AscendingOrder)
# table selections will change the total count of lines selected.
pane = LineListPane(table_view, linelist, sort_proxy, caller)
return pane, table_view
示例3: SampleLogsView
# 需要导入模块: from qtpy.QtWidgets import QTableView [as 别名]
# 或者: from qtpy.QtWidgets.QTableView import resizeColumnsToContents [as 别名]
class SampleLogsView(QSplitter):
"""Sample Logs View
This contains a table of the logs, a plot of the currently
selected logs, and the statistics of the selected log.
"""
def __init__(self, presenter, parent = None, name = '', isMD=False, noExp = 0):
super(SampleLogsView, self).__init__(parent)
self.presenter = presenter
self.setWindowTitle("{} sample logs".format(name))
self.setWindowFlags(Qt.Window)
# Create sample log table
self.table = QTableView()
self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
self.table.clicked.connect(self.presenter.clicked)
self.table.doubleClicked.connect(self.presenter.doubleClicked)
self.table.contextMenuEvent = self.tableMenu
self.addWidget(self.table)
frame_right = QFrame()
layout_right = QVBoxLayout()
#Add full_time and experimentinfo options
layout_options = QHBoxLayout()
if isMD:
layout_options.addWidget(QLabel("Experiment Info #"))
self.experimentInfo = QSpinBox()
self.experimentInfo.setMaximum(noExp-1)
self.experimentInfo.valueChanged.connect(self.presenter.changeExpInfo)
layout_options.addWidget(self.experimentInfo)
self.full_time = QCheckBox("Relative Time")
self.full_time.setChecked(True)
self.full_time.stateChanged.connect(self.presenter.plot_logs)
layout_options.addWidget(self.full_time)
layout_right.addLayout(layout_options)
# Sample log plot
self.fig = Figure()
self.canvas = FigureCanvas(self.fig)
self.canvas.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)
self.canvas.mpl_connect('button_press_event', self.presenter.plot_clicked)
self.ax = self.fig.add_subplot(111, projection='mantid')
layout_right.addWidget(self.canvas)
# Sample stats
self.create_stats_widgets()
layout_stats = QFormLayout()
layout_stats.addRow('', QLabel("Log Statistics"))
layout_stats.addRow('Min:', self.stats_widgets["minimum"])
layout_stats.addRow('Max:', self.stats_widgets["maximum"])
layout_stats.addRow('Mean:', self.stats_widgets["mean"])
layout_stats.addRow('Median:', self.stats_widgets["median"])
layout_stats.addRow('Std Dev:', self.stats_widgets["standard_deviation"])
layout_stats.addRow('Time Avg:', self.stats_widgets["time_mean"])
layout_stats.addRow('Time Std Dev:', self.stats_widgets["time_standard_deviation"])
layout_stats.addRow('Duration:', self.stats_widgets["duration"])
layout_right.addLayout(layout_stats)
frame_right.setLayout(layout_right)
self.addWidget(frame_right)
self.setStretchFactor(0,1)
self.resize(1200,800)
self.show()
def tableMenu(self, event):
"""Right click menu for table, can plot or print selected logs"""
menu = QMenu(self)
plotAction = menu.addAction("Plot selected")
plotAction.triggered.connect(self.presenter.new_plot_logs)
plotAction = menu.addAction("Print selected")
plotAction.triggered.connect(self.presenter.print_selected_logs)
menu.exec_(event.globalPos())
def set_model(self, model):
"""Set the model onto the table"""
self.model = model
self.table.setModel(self.model)
self.table.resizeColumnsToContents()
self.table.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)
def plot_selected_logs(self, ws, exp, rows):
"""Update the plot with the selected rows"""
self.ax.clear()
self.create_ax_by_rows(self.ax, ws, exp, rows)
self.fig.canvas.draw()
def new_plot_selected_logs(self, ws, exp, rows):
"""Create a new plot, in a separate window for selected rows"""
fig, ax = plt.subplots(subplot_kw={'projection': 'mantid'})
self.create_ax_by_rows(ax, ws, exp, rows)
fig.show()
def create_ax_by_rows(self, ax, ws, exp, rows):
"""Creates the plots for given rows onto axis ax"""
#.........这里部分代码省略.........