本文整理匯總了Python中qtpy.QtWidgets.QTableView類的典型用法代碼示例。如果您正苦於以下問題:Python QTableView類的具體用法?Python QTableView怎麽用?Python QTableView使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QTableView類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
def __init__(self, parent, data):
QTableView.__init__(self, parent)
self.model = DependenciesTableModel(self, data)
self.setModel(self.model)
self.delegate = DependenciesDelegate(self)
self.setItemDelegate(self.delegate)
self.setup_table()
示例2: resizeEvent
def resizeEvent(self, event):
"""Override Qt method"""
w = self.width()
width_start = 20
width_end = width_start
if self._advanced_mode:
action_cols = [const.COL_ACTION]
else:
action_cols = [const.COL_UPGRADE, const.COL_INSTALL,
const.COL_REMOVE, const.COL_DOWNGRADE]
self.setColumnWidth(const.COL_START, width_start)
self.setColumnWidth(const.COL_PACKAGE_TYPE, self.WIDTH_TYPE)
self.setColumnWidth(const.COL_NAME, self.WIDTH_NAME)
self.setColumnWidth(const.COL_VERSION, self.WIDTH_VERSION)
w_new = w - (width_start + self.WIDTH_ACTIONS + self.WIDTH_TYPE +
self.WIDTH_NAME + self.WIDTH_VERSION +
(len(action_cols))*self.WIDTH_ACTIONS + width_end)
self.setColumnWidth(const.COL_DESCRIPTION, w_new)
self.setColumnWidth(const.COL_END, width_end)
for col in action_cols:
self.setColumnWidth(col, self.WIDTH_ACTIONS)
QTableView.resizeEvent(self, event)
self.resize_rows()
示例3: __init__
def __init__(self, parent=None):
QTableView.__init__(self, parent)
self._parent = parent
self.finder = None
self.source_model = ShortcutsModel(self)
self.proxy_model = CustomSortFilterProxy(self)
self.last_regex = ''
self.proxy_model.setSourceModel(self.source_model)
self.proxy_model.setDynamicSortFilter(True)
self.proxy_model.setFilterKeyColumn(NAME)
self.proxy_model.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.setModel(self.proxy_model)
self.hideColumn(SEARCH_SCORE)
self.setItemDelegateForColumn(NAME, HTMLDelegate(self, margin=9))
self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setSelectionMode(QAbstractItemView.SingleSelection)
self.setSortingEnabled(True)
self.setEditTriggers(QAbstractItemView.AllEditTriggers)
self.selectionModel().selectionChanged.connect(self.selection)
self.verticalHeader().hide()
self.load_shortcuts()
示例4: keyPressEvent
def keyPressEvent(self, event):
"""Override Qt method"""
QTableView.keyPressEvent(self, event)
if event.key() in [Qt.Key_Enter, Qt.Key_Return]:
index = self.currentIndex()
self.action_pressed(index)
self.pressed_here = True
示例5: __init__
def __init__(self, parent, model):
QTableView.__init__(self, parent)
self.setModel(model)
self.frozen_table_view = FrozenTableView(self)
self.frozen_table_view.update_geometry()
self.setHorizontalScrollMode(1)
self.setVerticalScrollMode(1)
self.horizontalHeader().sectionResized.connect(self.update_section_width)
self.verticalHeader().sectionResized.connect(self.update_section_height)
self.frozen_table_view.verticalScrollBar().valueChanged.connect(
self.verticalScrollBar().setValue)
self.sort_old = [None]
self.header_class = self.horizontalHeader()
self.header_class.sectionClicked.connect(self.sortByColumn)
self.menu = self.setup_menu()
config_shortcut(self.copy, context='variable_explorer', name='copy',
parent=self)
self.horizontalScrollBar().valueChanged.connect(
lambda val: self.load_more_data(val, columns=True))
self.verticalScrollBar().valueChanged.connect(
lambda val: self.load_more_data(val, rows=True))
self.verticalScrollBar().valueChanged.connect(
self.frozen_table_view.verticalScrollBar().setValue)
示例6: _DatumTableWidget
class _DatumTableWidget(_DatumWidget):
def __init__(self, clasz, controller, datum=None, parent=None):
_DatumWidget.__init__(self, clasz, controller, datum, parent)
def _init_ui(self):
# Widgets
self._table = QTableView()
header = self._table.horizontalHeader()
mode = QHeaderView.Stretch
if os.environ[qtpy.QT_API] in qtpy.PYQT5_API:
header.setSectionResizeMode(mode)
else:
header.setResizeMode(mode)
# Layouts
layout = _DatumWidget._init_ui(self)
layout.addWidget(self._table)
return layout
def _create_model(self, datum):
raise NotImplementedError
def setDatum(self, datum):
_DatumWidget.setDatum(self, datum)
if datum is not None:
model = self._create_model(datum)
else:
model = None
self._table.setModel(model)
示例7: __init__
def __init__(self, parent):
QTableView.__init__(self, parent)
self._model = None
# Setting up actions
self.date_dayfirst_action = create_action(self, "dayfirst",
triggered=ft_partial(self.parse_to_type, atype="date", dayfirst=True))
self.date_monthfirst_action = create_action(self, "monthfirst",
triggered=ft_partial(self.parse_to_type, atype="date", dayfirst=False))
self.perc_action = create_action(self, "perc",
triggered=ft_partial(self.parse_to_type, atype="perc"))
self.acc_action = create_action(self, "account",
triggered=ft_partial(self.parse_to_type, atype="account"))
self.str_action = create_action(self, "unicode",
triggered=ft_partial(self.parse_to_type, atype="unicode"))
self.int_action = create_action(self, "int",
triggered=ft_partial(self.parse_to_type, atype="int"))
self.float_action = create_action(self, "float",
triggered=ft_partial(self.parse_to_type, atype="float"))
# Setting up menus
self.date_menu = QMenu()
self.date_menu.setTitle("Date")
add_actions( self.date_menu, (self.date_dayfirst_action,
self.date_monthfirst_action))
self.parse_menu = QMenu(self)
self.parse_menu.addMenu(self.date_menu)
add_actions( self.parse_menu, (self.perc_action, self.acc_action))
self.parse_menu.setTitle("String to")
self.opt_menu = QMenu(self)
self.opt_menu.addMenu(self.parse_menu)
add_actions( self.opt_menu, (self.str_action, self.int_action,
self.float_action))
示例8: keyPressEvent
def keyPressEvent(self, event):
"""
Override Qt method.
"""
index = self.currentIndex()
key = event.key()
if key in [Qt.Key_Enter, Qt.Key_Return]:
# self.action_pressed(index)
self.setCurrentIndex(self.proxy_model.index(index.row(),
const.COL_ACTION))
self.pressed_here = True
elif key in [Qt.Key_Tab]:
new_row = index.row() + 1
if not self.proxy_model or new_row == self.proxy_model.rowCount():
self.sig_next_focus.emit()
else:
new_index = self.proxy_model.index(new_row, 0)
self.setCurrentIndex(new_index)
elif key in [Qt.Key_Backtab]:
new_row = index.row() - 1
if new_row < 0:
self.sig_previous_focus.emit()
else:
new_index = self.proxy_model.index(new_row, 0)
self.setCurrentIndex(new_index)
else:
QTableView.keyPressEvent(self, event)
self.update_visible_rows()
示例9: resizeEvent
def resizeEvent(self, event):
"""Update the frozen column dimensions.
Updates takes place when the enclosing window of this
table reports a dimension change
"""
QTableView.resizeEvent(self, event)
self.frozen_table_view.update_geometry()
示例10: __init__
def __init__(self, parent, data):
QTableView.__init__(self, parent)
self.model = BreakpointTableModel(self, data)
self.setModel(self.model)
self.delegate = BreakpointDelegate(self)
self.setItemDelegate(self.delegate)
self.setup_table()
示例11: scrollTo
def scrollTo(self, index, hint):
"""Scroll the table.
It is necessary to ensure that the item at index is visible.
The view will try to position the item according to the
given hint. This method does not takes effect only if
the frozen column is scrolled.
"""
if index.column() > 1:
QTableView.scrollTo(self, index, hint)
示例12: mousePressEvent
def mousePressEvent(self, event):
"""Override Qt method"""
QTableView.mousePressEvent(self, event)
self.current_index = self.currentIndex()
if event.button() == Qt.LeftButton:
pos = QPoint(event.x(), event.y())
index = self.indexAt(pos)
self.action_pressed(index)
elif event.button() == Qt.RightButton:
self.context_menu_requested(event)
示例13: resizeEvent
def resizeEvent(self, event):
"""Override Qt method"""
w = self.width()
self.setColumnWidth(const.NAME, self.WIDTH_NAME)
self.setColumnWidth(const.VERSION, self.WIDTH_VERSION)
w_new = w - (self.WIDTH_NAME + self.WIDTH_VERSION + (len(const.ACTION_COLUMNS) + 1) * self.WIDTH_ACTIONS)
self.setColumnWidth(const.DESCRIPTION, w_new)
for col in const.ACTION_COLUMNS:
self.setColumnWidth(col, self.WIDTH_ACTIONS)
QTableView.resizeEvent(self, event)
self.resize_rows()
示例14: __init__
def __init__(self, parent, model):
QTableView.__init__(self, parent)
self.setModel(model)
self.sort_old = [None]
self.header_class = self.horizontalHeader()
self.header_class.sectionClicked.connect(self.sortByColumn)
self.menu = self.setup_menu()
new_shortcut(QKeySequence.Copy, self, self.copy)
self.horizontalScrollBar().valueChanged.connect(
lambda val: self.load_more_data(val, columns=True))
self.verticalScrollBar().valueChanged.connect(
lambda val: self.load_more_data(val, rows=True))
示例15: mousePressEvent
def mousePressEvent(self, event):
"""Override Qt method"""
QTableView.mousePressEvent(self, event)
self.current_index = self.currentIndex()
column = self.current_index.column()
if event.button() == Qt.LeftButton and column == const.COL_ACTION:
pos = QPoint(event.x(), event.y())
index = self.indexAt(pos)
self.action_pressed(index)
self.context_menu_requested(event)
elif event.button() == Qt.RightButton:
self.context_menu_requested(event, right_click=True)
self.update_visible_rows()