本文整理汇总了Python中PyQt5.QtWidgets.QTableView.verticalHeader方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.verticalHeader方法的具体用法?Python QTableView.verticalHeader怎么用?Python QTableView.verticalHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.verticalHeader方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
def main(args):
app = QApplication(args)
page = QSplitter()
data = Model(1000, 10, page)
selections = QItemSelectionModel(data)
table = QTableView()
table.setModel(data)
table.setSelectionModel(selections)
table.horizontalHeader().setSectionsMovable(True)
table.verticalHeader().setSectionsMovable(True)
# Set StaticContents to enable minimal repaints on resizes.
table.viewport().setAttribute(Qt.WA_StaticContents)
page.addWidget(table)
tree = QTreeView()
tree.setModel(data)
tree.setSelectionModel(selections)
tree.setUniformRowHeights(True)
tree.header().setStretchLastSection(False)
tree.viewport().setAttribute(Qt.WA_StaticContents)
# Disable the focus rect to get minimal repaints when scrolling on Mac.
tree.setAttribute(Qt.WA_MacShowFocusRect, False)
page.addWidget(tree)
list = QListView()
list.setModel(data)
list.setSelectionModel(selections)
list.setViewMode(QListView.IconMode)
list.setSelectionMode(QAbstractItemView.ExtendedSelection)
list.setAlternatingRowColors(False)
list.viewport().setAttribute(Qt.WA_StaticContents)
list.setAttribute(Qt.WA_MacShowFocusRect, False)
page.addWidget(list)
page.setWindowIcon(QIcon(images_dir + '/interview.png'))
page.setWindowTitle("Interview")
page.show()
return app.exec_()
示例2: SetupUI
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
def SetupUI(self, w):
info("SetupUI")
# Search bar
lblName = QLabel('Search')
lblResults = QLabel('Results')
# Plugin table
ledtName = QLineEdit()
tblResults = QTableView()
tblResultsModel = PluginTableModel(self.available_plugins, Plugin.SQLITE_COLUMNS, w)
tblResults.setModel( tblResultsModel )
tblResults.horizontalHeader().setStretchLastSection(True)
tblResults.verticalHeader().setVisible(False)
tblResults.resizeColumnsToContents()
tblResults.setSortingEnabled(True)
tblResults.setFont( QFont("Courier New", 8) )
tblResults.setShowGrid(False)
## event handlers
ledtName.textChanged.connect(self.OnSearchFieldChange)
# Button row
btnUpdate = QPushButton("Refresh Plugins List")
btnInstall = QPushButton("Install")
## event handlers
btnUpdate.clicked.connect(self.RefreshPluginsList)
btnInstall.clicked.connect(self.InstallSelected)
grid = QGridLayout()
grid.addWidget(lblName, 1, 0)
grid.addWidget(ledtName, 1, 1)
grid.addWidget(lblResults, 2, 0)
grid.addWidget(tblResults, 2, 1, 5, 1)
vbox = QVBoxLayout()
vbox.addStretch(1)
vbox.addWidget(btnUpdate)
vbox.addWidget(btnInstall)
wButtons = QWidget()
wButtons.setLayout(vbox)
grid.addWidget(wButtons, 5, 1, 4, 1)
w.setLayout(grid)
return
示例3: ProblemDialog
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class ProblemDialog(QDialog):
def __init__(self, parent, model, **kwargs):
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
super().__init__(parent, flags, **kwargs)
self._setupUi()
self.model = model
self.model.view = self
self.table = ProblemTable(self.model.problem_table, view=self.tableView)
self.revealButton.clicked.connect(self.model.reveal_selected_dupe)
self.closeButton.clicked.connect(self.accept)
def _setupUi(self):
self.setWindowTitle(tr("Problems!"))
self.resize(413, 323)
self.verticalLayout = QVBoxLayout(self)
self.label = QLabel(self)
msg = tr(
"There were problems processing some (or all) of the files. The cause of "
"these problems are described in the table below. Those files were not "
"removed from your results."
)
self.label.setText(msg)
self.label.setWordWrap(True)
self.verticalLayout.addWidget(self.label)
self.tableView = QTableView(self)
self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.tableView.setSelectionMode(QAbstractItemView.SingleSelection)
self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
self.tableView.setShowGrid(False)
self.tableView.horizontalHeader().setStretchLastSection(True)
self.tableView.verticalHeader().setDefaultSectionSize(18)
self.tableView.verticalHeader().setHighlightSections(False)
self.verticalLayout.addWidget(self.tableView)
self.horizontalLayout = QHBoxLayout()
self.revealButton = QPushButton(self)
self.revealButton.setText(tr("Reveal Selected"))
self.horizontalLayout.addWidget(self.revealButton)
spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.closeButton = QPushButton(self)
self.closeButton.setText(tr("Close"))
self.closeButton.setDefault(True)
self.horizontalLayout.addWidget(self.closeButton)
self.verticalLayout.addLayout(self.horizontalLayout)
示例4: draw_table
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
def draw_table():
tv = QTableView()
tv.setMinimumSize(400, 400)
tv.setShowGrid(False)
vh = tv.verticalHeader()
vh.setVisible(False)
hh = tv.horizontalHeader()
hh.setStretchLastSection(True)
tv.setSortingEnabled(True)
return tv
示例5: TableWindow
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class TableWindow(QMainWindow):
def __init__(self, title):
super(TableWindow, self).__init__()
# Set up the user interface from Designer.
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.setWindowTitle(title)
self.layout = QHBoxLayout(self.ui.centralwidget)
self.ui.windowTitle = title
self.ui.centralwidget.setLayout(self.layout)
self.tableView = QTableView()
self.layout.addWidget(self.tableView)
self.tableView.setHorizontalHeader(MyHeaderView(Qt.Horizontal))
self.tableView.setVerticalHeader(MyHeaderView(Qt.Vertical))
def setModel(self, model):
self.tableView.setModel(model)
margins = self.layout.contentsMargins()
self.resize((
margins.left() + margins.right() + self.tableView.frameWidth() * 2 + self.tableView.verticalHeader().width() + self.tableView.horizontalHeader().length()),
self.height())
示例6: IgnoreListDialog
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class IgnoreListDialog(QDialog):
def __init__(self, parent, model, **kwargs):
flags = Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowSystemMenuHint
super().__init__(parent, flags, **kwargs)
self._setupUi()
self.model = model
self.model.view = self
self.table = IgnoreListTable(self.model.ignore_list_table, view=self.tableView)
self.removeSelectedButton.clicked.connect(self.model.remove_selected)
self.clearButton.clicked.connect(self.model.clear)
self.closeButton.clicked.connect(self.accept)
def _setupUi(self):
self.setWindowTitle(tr("Ignore List"))
self.resize(540, 330)
self.verticalLayout = QVBoxLayout(self)
self.tableView = QTableView()
self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.tableView.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
self.tableView.setShowGrid(False)
self.tableView.horizontalHeader().setStretchLastSection(True)
self.tableView.verticalHeader().setDefaultSectionSize(18)
self.tableView.verticalHeader().setHighlightSections(False)
self.tableView.verticalHeader().setVisible(False)
self.verticalLayout.addWidget(self.tableView)
self.removeSelectedButton = QPushButton(tr("Remove Selected"))
self.clearButton = QPushButton(tr("Clear"))
self.closeButton = QPushButton(tr("Close"))
self.verticalLayout.addLayout(
horizontalWrap([
self.removeSelectedButton, self.clearButton,
None, self.closeButton
])
)
#--- model --> view
def show(self):
super().show()
示例7: ExportPanel
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class ExportPanel(Panel):
FIELDS = []
PERSISTENT_NAME = 'exportPanel'
def __init__(self, model, mainwindow):
Panel.__init__(self, mainwindow)
self.setAttribute(Qt.WA_DeleteOnClose)
self.mainwindow = mainwindow
self._setupUi()
self.model = model
self.accountTable = ExportAccountTable(model=self.model.account_table, view=self.tableView)
self.exportTypeButtons.buttonClicked[int].connect(self.exportTypeSelected)
self.exportFormatButtons.buttonClicked[int].connect(self.exportFormatSelected)
self.buttonBox.rejected.connect(self.reject)
self.exportButton.clicked.connect(self.exportButtonClicked)
def _setupUi(self):
self.setWindowTitle(tr("Export Options"))
self.mainLayout = QVBoxLayout(self)
self.label1 = QLabel(tr("Which accounts do you want to export?"), self)
self.mainLayout.addWidget(self.label1)
self.exportTypeButtons = QButtonGroup(self)
self.exportAllButton = QRadioButton(tr("All"), self)
self.mainLayout.addWidget(self.exportAllButton)
self.exportTypeButtons.addButton(self.exportAllButton, ExportType.All)
self.exportAllButton.setChecked(True)
self.exportSelectedButton = QRadioButton(tr("Selected"), self)
self.mainLayout.addWidget(self.exportSelectedButton)
self.exportTypeButtons.addButton(self.exportSelectedButton, ExportType.Selected)
self.tableView = QTableView(self)
self.tableView.setSelectionMode(QAbstractItemView.SingleSelection)
self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
self.tableView.verticalHeader().setVisible(False)
self.tableView.verticalHeader().setDefaultSectionSize(18)
self.mainLayout.addWidget(self.tableView)
self.label2 = QLabel(tr("Export format:"), self)
self.mainLayout.addWidget(self.label2)
self.exportFormatButtons = QButtonGroup(self)
self.exportAsQIFButton = QRadioButton("QIF", self)
self.mainLayout.addWidget(self.exportAsQIFButton)
self.exportFormatButtons.addButton(self.exportAsQIFButton, ExportFormat.QIF)
self.exportAsQIFButton.setChecked(True)
self.exportAsCSVButton = QRadioButton("CSV", self)
self.mainLayout.addWidget(self.exportAsCSVButton)
self.exportFormatButtons.addButton(self.exportAsCSVButton, ExportFormat.CSV)
self.label3 = QLabel(tr("Export scope:"))
self.mainLayout.addWidget(self.label3)
self.dateRangeOnlyCheckbox = QCheckBox(tr("Current date range only"))
self.mainLayout.addWidget(self.dateRangeOnlyCheckbox)
self.buttonBox = QDialogButtonBox(self)
self.buttonBox.setOrientation(Qt.Horizontal)
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel)
self.exportButton = self.buttonBox.addButton(tr("Export"), QDialogButtonBox.ActionRole)
self.mainLayout.addWidget(self.buttonBox)
#--- Overrides
def _loadFields(self):
self.exportAllButton.setChecked(self.model.export_all)
self.exportAsQIFButton.setChecked(self.model.export_format == ExportFormat.QIF)
self.dateRangeOnlyCheckbox.setChecked(self.model.current_daterange_only)
def _saveFields(self):
self.model.current_daterange_only = self.dateRangeOnlyCheckbox.isChecked()
#--- Event Handlers
def exportButtonClicked(self):
title = tr("Export")
fileext = 'qif' if self.model.export_format == ExportFormat.QIF else 'csv'
filters = tr("{0} Files (*.{1})").format(fileext.upper(), fileext)
filename = 'export.{0}'.format(fileext)
docpath = str(QFileDialog.getSaveFileName(self.mainwindow, title, filename, filters))
if docpath:
self.model.export_path = docpath
self.accept()
def exportTypeSelected(self, typeId):
self.model.export_all = typeId == ExportType.All
def exportFormatSelected(self, typeId):
self.model.export_format = typeId
#--- model --> view
def set_table_enabled(self, enabled):
self.tableView.setEnabled(enabled)
def set_export_button_enabled(self, enabled):
self.exportButton.setEnabled(enabled)
示例8: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.currentPath = QDir.homePath()
self.model = ImageModel(self)
centralWidget = QWidget()
self.view = QTableView()
self.view.setShowGrid(False)
self.view.horizontalHeader().hide()
self.view.verticalHeader().hide()
self.view.horizontalHeader().setMinimumSectionSize(1)
self.view.verticalHeader().setMinimumSectionSize(1)
self.view.setModel(self.model)
delegate = PixelDelegate(self)
self.view.setItemDelegate(delegate)
pixelSizeLabel = QLabel("Pixel size:")
pixelSizeSpinBox = QSpinBox()
pixelSizeSpinBox.setMinimum(4)
pixelSizeSpinBox.setMaximum(32)
pixelSizeSpinBox.setValue(12)
fileMenu = QMenu("&File", self)
openAction = fileMenu.addAction("&Open...")
openAction.setShortcut("Ctrl+O")
self.printAction = fileMenu.addAction("&Print...")
self.printAction.setEnabled(False)
self.printAction.setShortcut("Ctrl+P")
quitAction = fileMenu.addAction("E&xit")
quitAction.setShortcut("Ctrl+Q")
helpMenu = QMenu("&Help", self)
aboutAction = helpMenu.addAction("&About")
self.menuBar().addMenu(fileMenu)
self.menuBar().addSeparator()
self.menuBar().addMenu(helpMenu)
openAction.triggered.connect(self.chooseImage)
self.printAction.triggered.connect(self.printImage)
quitAction.triggered.connect(QApplication.instance().quit)
aboutAction.triggered.connect(self.showAboutBox)
pixelSizeSpinBox.valueChanged.connect(delegate.setPixelSize)
pixelSizeSpinBox.valueChanged.connect(self.updateView)
controlsLayout = QHBoxLayout()
controlsLayout.addWidget(pixelSizeLabel)
controlsLayout.addWidget(pixelSizeSpinBox)
controlsLayout.addStretch(1)
mainLayout = QVBoxLayout()
mainLayout.addWidget(self.view)
mainLayout.addLayout(controlsLayout)
centralWidget.setLayout(mainLayout)
self.setCentralWidget(centralWidget)
self.setWindowTitle("Pixelator")
self.resize(640, 480)
def chooseImage(self):
fileName, _ = QFileDialog.getOpenFileName(self, "Choose an Image",
self.currentPath, '*')
if fileName:
self.openImage(fileName)
def openImage(self, fileName):
image = QImage()
if image.load(fileName):
self.model.setImage(image)
if not fileName.startswith(':/'):
self.currentPath = fileName
self.setWindowTitle("%s - Pixelator" % self.currentPath)
self.printAction.setEnabled(True)
self.updateView()
def printImage(self):
if self.model.rowCount(QModelIndex()) * self.model.columnCount(QModelIndex()) > 90000:
answer = QMessageBox.question(self, "Large Image Size",
"The printed image may be very large. Are you sure that "
"you want to print it?",
QMessageBox.Yes | QMessageBox.No)
if answer == QMessageBox.No:
return
printer = QPrinter(QPrinter.HighResolution)
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle("Print Image")
#.........这里部分代码省略.........
示例9: ZoteroTableWidget
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class ZoteroTableWidget(QWidget):
def __init__(self, settings, directory, check_id_fct, annotations_path, parent=None):
super().__init__(parent)
# FIXME Delayed refactoring of check_id_fct and annotations_path.
# Variables section.
library_id = settings["libraryID"]
library_type = settings["libraryType"]
api_key = settings["apiKey"]
self._zotero = ZoteroWrap(library_id, library_type, api_key, directory)
# Widgets section.
model = ZoteroTableModel(self._zotero, check_id_fct, annotations_path)
model.load()
proxy_model = QSortFilterProxyModel()
proxy_model.setSourceModel(model)
proxy_model.setDynamicSortFilter(True)
proxy_model.setFilterCaseSensitivity(Qt.CaseInsensitive)
proxy_model.setFilterKeyColumn(-1) # NB: All columns.
self.view = QTableView(self)
self.view.setModel(proxy_model)
self.view.setCornerButtonEnabled(False)
self.view.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.view.setSelectionBehavior(QAbstractItemView.SelectRows)
self.view.setSelectionMode(QAbstractItemView.SingleSelection)
# NB: Triggers a call to sortByColumn() which sorts by the first column.
self.view.setSortingEnabled(True)
self.view.setWordWrap(False)
self.view.verticalHeader().hide()
self.filter_edit = FilterEdit(self.view)
# NB: The thread does not begin executing until start() is called.
self.refresh_thread = ZoteroRefreshThread(model, self)
# Layouts section.
header_layout = QFormLayout()
header_layout.addRow("Filter:", self.filter_edit)
header_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
utils.configure_form_layout(header_layout)
main_layout = QVBoxLayout()
main_layout.addLayout(header_layout)
main_layout.addWidget(self.view)
self.setLayout(main_layout)
# Signals section.
self.filter_edit.textChanged.connect(proxy_model.setFilterFixedString)
self.refresh_thread.started.connect(self.refresh_started)
self.refresh_thread.finished.connect(self.refresh_finished)
# def __del__(self):
# # FIXME Delayed refactoring. Not called when application is closed. Incorrect parent use?
# # NB: Exiting the program when another thread is still busy is a programming error.
# # NB: Call QThread::quit() if the thread has an event loop.
# print("DEBUG: ZoteroTableWidget.__del__()")
# # TODO Display an information dialog.
# self.refresh_thread.wait()
# print("DEBUG: ZoteroRefreshThread.wait() returned")
# Slots section.
@pyqtSlot()
def refresh_database(self):
"""Start the thread refreshing the Zotero data.
If the thread is already running, it is not restarted.
"""
self.refresh_thread.start()
@pyqtSlot()
def refresh_started(self):
"""Disable the Zotero widget when the thread refreshing its data runs.
Disable handling of keyboard/mouse events to ensure a thread-safe refresh.
"""
# TODO Display an information on top of the disabled widget.
self.setDisabled(True)
@pyqtSlot()
def refresh_finished(self):
"""Enable the Zotero widget when the thread refreshing its data finishes.
Reset the selection model of the view in case of new/deleted references.
Enable again the handling of keyboard/mouse events.
"""
self.view.selectionModel().reset()
self.setEnabled(True)
@pyqtSlot()
def add_reference(self):
"""Display the form for and handle the creation of a new reference."""
dialog = ZoteroReferenceDialog(self._zotero.reference_templates, self)
#.........这里部分代码省略.........
示例10: CSVOptionsWindow
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class CSVOptionsWindow(QWidget):
def __init__(self, mainwindow):
QWidget.__init__(self, mainwindow, Qt.Window)
self._setupUi()
self.doc = mainwindow.doc
self.model = mainwindow.model.csv_options
self.tableModel = CSVOptionsTableModel(self.model, self.tableView)
self.model.view = self
self.encodingComboBox.addItems(SUPPORTED_ENCODINGS)
self.cancelButton.clicked.connect(self.hide)
self.continueButton.clicked.connect(self.model.continue_import)
self.targetComboBox.currentIndexChanged.connect(self.targetIndexChanged)
self.layoutComboBox.currentIndexChanged.connect(self.layoutIndexChanged)
self.rescanButton.clicked.connect(self.rescanClicked)
def _setupUi(self):
self.setWindowTitle(tr("CSV Options"))
self.resize(526, 369)
self.verticalLayout = QVBoxLayout(self)
msg = tr(
"Specify which CSV columns correspond to which transaction fields. You must also "
"uncheck the \"Import\" column for lines that don\'t represent a transaction "
"(header, footer, comments)."
)
self.label = QLabel(msg)
self.label.setWordWrap(True)
self.verticalLayout.addWidget(self.label)
self.gridLayout = QGridLayout()
self.label_2 = QLabel(tr("Layout:"))
self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)
self.layoutComboBox = QComboBox(self)
self.layoutComboBox.setMinimumSize(QtCore.QSize(160, 0))
self.gridLayout.addWidget(self.layoutComboBox, 0, 1, 1, 1)
self.label_4 = QLabel(tr("Delimiter:"))
self.gridLayout.addWidget(self.label_4, 0, 3, 1, 1)
self.fieldSeparatorEdit = QLineEdit(self)
self.fieldSeparatorEdit.setMaximumSize(QtCore.QSize(30, 16777215))
self.gridLayout.addWidget(self.fieldSeparatorEdit, 0, 4, 1, 1)
self.targetComboBox = QComboBox(self)
self.gridLayout.addWidget(self.targetComboBox, 1, 1, 1, 1)
self.label_3 = QLabel(tr("Target:"))
self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)
self.encodingComboBox = QComboBox(self)
self.gridLayout.addWidget(self.encodingComboBox, 1, 4, 1, 1)
spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
self.gridLayout.addItem(spacerItem, 2, 2, 1, 1)
self.horizontalLayout_2 = QHBoxLayout()
self.horizontalLayout_2.setSpacing(0)
spacerItem1 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem1)
self.rescanButton = QPushButton(tr("Rescan"))
sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.rescanButton.sizePolicy().hasHeightForWidth())
self.rescanButton.setSizePolicy(sizePolicy)
self.horizontalLayout_2.addWidget(self.rescanButton)
self.gridLayout.addLayout(self.horizontalLayout_2, 2, 3, 1, 2)
self.label_5 = QLabel(tr("Encoding:"))
self.gridLayout.addWidget(self.label_5, 1, 3, 1, 1)
self.verticalLayout.addLayout(self.gridLayout)
self.tableView = QTableView(self)
self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
self.tableView.setShowGrid(False)
self.tableView.horizontalHeader().setHighlightSections(False)
self.tableView.verticalHeader().setVisible(False)
self.tableView.verticalHeader().setDefaultSectionSize(18)
self.verticalLayout.addWidget(self.tableView)
self.horizontalLayout = QHBoxLayout()
spacerItem2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem2)
self.cancelButton = QPushButton(tr("Cancel"))
self.cancelButton.setShortcut("Esc")
self.horizontalLayout.addWidget(self.cancelButton)
self.continueButton = QPushButton(tr("Continue Import"))
self.continueButton.setDefault(True)
self.horizontalLayout.addWidget(self.continueButton)
self.verticalLayout.addLayout(self.horizontalLayout)
# --- Private
def _newLayout(self):
title = tr("New Layout")
msg = tr("Choose a name for your new layout:")
name, ok = QInputDialog.getText(self, title, msg)
if ok and name:
self.model.new_layout(name)
def _renameLayout(self):
title = tr("Rename Layout")
msg = tr("Choose a name for your layout:")
name, ok = QInputDialog.getText(self, title, msg)
if ok and name:
self.model.rename_selected_layout(name)
# --- Event Handling
def layoutIndexChanged(self, index):
# This one is a little complicated. We want to only be able to select the layouts. If
# anything else is clicked, we revert back to the old index. If the item has user data,
#.........这里部分代码省略.........
示例11: ListView
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class ListView(QStackedWidget):
PAGE_EMPTY = 0
PAGE_LISTVIEW = 1
def __init__(self, parent = None):
super(ListView, self).__init__(parent=parent)
self.emptyMessage = QLabel("no elements defined yet")
self.emptyMessage.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter )
self.emptyMessage.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.addWidget(self.emptyMessage)
self._table = QTableView()
self.addWidget(self._table)
self._table.clicked.connect(self.tableViewCellClicked)
self._table.doubleClicked.connect(self.tableViewCellDoubleClicked)
self._table.verticalHeader().sectionMoved.connect(self.rowMovedTest)
self._table.setShowGrid(False)
def resetEmptyMessage(self,pystring):
self.emptyMessage.setText(pystring)
def tableViewCellClicked(self, modelIndex):
'''
Reimplemt this function to get interaction when double click
:param modelIndex:
'''
# if (modelIndex.column() == self.model.ColumnID.Delete and
# not self._table.model().flags(modelIndex) == Qt.NoItemFlags):
# self._table.model().removeRow(modelIndex.row())
#
def tableViewCellDoubleClicked(self, modelIndex):
'''
Reimplement this function to get interaction when single click
:param modelIndex:
'''
# if modelIndex.column() == self.model.ColumnID.Color:
# self._colorDialog.setBrushColor(self._table.model()[modelIndex.row()].brushColor())
# self._colorDialog.setPmapColor (self._table.model()[modelIndex.row()].pmapColor())
# self._colorDialog.exec_()
# #print "brush color = {}".format(self._colorDialog.brushColor().name())
# #print "pmap color = {}".format(self._colorDialog.pmapColor().name())
# self._table.model().setData(modelIndex, (self._colorDialog.brushColor(),
# self._colorDialog.pmapColor ()))
def rowMovedTest(self, logicalIndex, oldVisualIndex, newVisualIndex):
logger.debug( "{} {} {}".format(logicalIndex, oldVisualIndex, newVisualIndex) )
def _setListViewLook(self):
table = self._table
#table.setDragEnabled(True)
table.setAcceptDrops(True)
table.setFocusPolicy(Qt.NoFocus)
table.setShowGrid(False)
table.horizontalHeader().hide()
table.verticalHeader().hide()
#table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
table.setSelectionMode(QAbstractItemView.SingleSelection)
table.setSelectionBehavior(QAbstractItemView.SelectRows)
def selectRow(self, *args, **kwargs):
self._table.selectRow(*args, **kwargs)
def _onRowsChanged(self, parent, start, end):
model = self._table.model()
if model and model.rowCount() > 0:
self.setCurrentIndex(self.PAGE_LISTVIEW)
else:
self.setCurrentIndex(self.PAGE_EMPTY)
if self.parent()!=None: self.parent().updateGeometry()
def setModel(self, model):
QTableView.setModel(self._table, model)
self._table.setSelectionModel(model._selectionModel)
if model.rowCount() > 0:
self.setCurrentIndex(self.PAGE_LISTVIEW)
else:
self.setCurrentIndex(self.PAGE_EMPTY)
model.rowsInserted.connect(self._onRowsChanged)
model.rowsRemoved.connect(self._onRowsChanged)
self.model=model
self._setListViewLook()
@property
def allowDelete(self):
return not self._table.isColumnHidden(self.model.ColumnID.Delete)
@allowDelete.setter
def allowDelete(self, allow):
self._table.setColumnHidden(self.model.ColumnID.Delete, not allow)
#.........这里部分代码省略.........
示例12: FreezeTableWidget
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class FreezeTableWidget(QTableView):
def __init__(self, model):
super(FreezeTableWidget, self).__init__()
self.setModel(model)
self.frozenTableView = QTableView(self)
self.init()
self.horizontalHeader().sectionResized.connect(self.updateSectionWidth)
self.verticalHeader().sectionResized.connect(self.updateSectionHeight)
self.frozenTableView.verticalScrollBar().valueChanged.connect(
self.verticalScrollBar().setValue)
self.verticalScrollBar().valueChanged.connect(
self.frozenTableView.verticalScrollBar().setValue)
def init(self):
self.frozenTableView.setModel(self.model())
self.frozenTableView.setFocusPolicy(Qt.NoFocus)
self.frozenTableView.verticalHeader().hide()
self.frozenTableView.horizontalHeader().setSectionResizeMode(
QHeaderView.Fixed)
self.viewport().stackUnder(self.frozenTableView)
self.frozenTableView.setStyleSheet('''
QTableView { border: none;
background-color: #8EDE21;
selection-background-color: #999;
}''') # for demo purposes
self.frozenTableView.setSelectionModel(self.selectionModel())
for col in range(1, self.model().columnCount()):
self.frozenTableView.setColumnHidden(col, True)
self.frozenTableView.setColumnWidth(0, self.columnWidth(0))
self.frozenTableView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.frozenTableView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.frozenTableView.show()
self.updateFrozenTableGeometry()
self.setHorizontalScrollMode(self.ScrollPerPixel)
self.setVerticalScrollMode(self.ScrollPerPixel)
self.frozenTableView.setVerticalScrollMode(self.ScrollPerPixel)
def updateSectionWidth(self, logicalIndex, oldSize, newSize):
if self.logicalIndex == 0:
self.frozenTableView.setColumnWidth(0, newSize)
self.updateFrozenTableGeometry()
def updateSectionHeight(self, logicalIndex, oldSize, newSize):
self.frozenTableView.setRowHeight(logicalIndex, newSize)
def resizeEvent(self, event):
super(FreezeTableWidget, self).resizeEvent(event)
self.updateFrozenTableGeometry()
def moveCursor(self, cursorAction, modifiers):
current = super(FreezeTableWidget, self).moveCursor(cursorAction, modifiers)
if (cursorAction == self.MoveLeft and
self.current.column() > 0 and
self.visualRect(current).topLeft().x() <
self.frozenTableView.columnWidth(0)):
newValue = (self.horizontalScrollBar().value() +
self.visualRect(current).topLeft().x() -
self.frozenTableView.columnWidth(0))
self.horizontalScrollBar().setValue(newValue)
return current
def scrollTo(self, index, hint):
if index.column() > 0:
super(FreezeTableWidget, self).scrollTo(index, hint)
def updateFrozenTableGeometry(self):
self.frozenTableView.setGeometry(
self.verticalHeader().width() + self.frameWidth(),
self.frameWidth(), self.columnWidth(0),
self.viewport().height() + self.horizontalHeader().height())
示例13: ExportFrame
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import verticalHeader [as 别名]
class ExportFrame(QFrame):
def get_existing_resync_file(self, resync_file):
# get the existing resync_file as file URI.
# return 'file://'+self.config.get_cfg_resync_dir()+'/'+resync_file
p = PurePath(self.config.cfg_resync_dir(), resync_file)
return p.as_uri()
def __init__(self, parent):
super().__init__(parent)
self.logger = logging.getLogger(__name__)
self.config = Configuration()
self.filenames = []
self.data = ""
# left part of frame
header_left = [_("Relative Path"), _("Name"), _("Size"), _("Date Modified")]
self.file_model = FileTableModel(self, header_left, [])
self.file_view = QTableView()
self.file_view.setModel(self.file_model)
self.file_view.setSortingEnabled(True)
self.file_view.setAlternatingRowColors(True)
self.file_view.setShowGrid(False)
# adjustments
self.file_view.verticalHeader().setDefaultSectionSize(22)
# self.file_view.horizontalHeader().setDefaultSectionSize(self.file_view.width()/len(header))
# self.file_view.horizontalHeader().setStretchLastSection(True)
self.file_view.setSelectionMode(QAbstractItemView.SingleSelection)
self.file_view.setSelectionBehavior(QAbstractItemView.SelectRows)
self.file_view.doubleClicked.connect(self.file_view_doubleclicked)
# self.file_view.clicked.connect(self.file_view_clicked)
self.file_view.selectionModel().selectionChanged.connect(self.file_view_selection_changed)
# self.file_view.setContextMenuPolicy(Qt.CustomContextMenu)
# self.file_view.customContextMenuRequested.connect(self.file_view_context_menu_requested)
# self.lb_nsfc = QLabel("")
self.lb_path = QLabel("")
self.lb_path.setFont(QFont("SansSerif", 10))
self.pb_select = QPushButton(_("Select"))
self.pb_select.clicked.connect(self.show_explorer)
# right part of frame
header_right = [_("Set Name"), _("Files"), _("New Files"), _("Update Files"), _("Unchanged Files")]
self.overview_model = OverviewTableModel(self, header_right, [])
self.overview = QTableView()
self.overview.setModel(self.overview_model)
self.overview.setAlternatingRowColors(True)
self.overview.setShowGrid(False)
self.overview.verticalHeader().setDefaultSectionSize(22)
self.pb_publish = QPushButton(_("Publish"))
self.pb_publish.clicked.connect(self.pb_publish_clicked)
self.pb_zip = QPushButton(_("Create Zip"))
self.pb_zip.clicked.connect(self.pb_zip_clicked)
self.__init_ui__()
def __init_ui__(self):
vbox = QVBoxLayout()
splitter = QSplitter()
splitter.addWidget(self.file_view)
splitter.addWidget(self.overview)
vbox.addWidget(splitter, 1)
vbox.addWidget(self.lb_path)
button_box = QHBoxLayout()
button_box.addWidget(self.pb_select)
button_box.addStretch(1)
button_box.addWidget(self.pb_publish)
button_box.addWidget(self.pb_zip)
vbox.addLayout(button_box)
self.setLayout(vbox)
def file_view_doubleclicked(self, index):
path = self.file_model.full_path(index.row())
webbrowser.open_new(PurePath(path).as_uri())
def file_view_clicked(self, index):
pass
def file_view_selection_changed(self, selected, deselected):
# selected, deselected: PyQt5.QtCore.QItemSelection
sindexes = selected.indexes()
if len(sindexes) > 0:
index = sindexes[0]
path = self.file_model.full_path(index.row())
self.lb_path.setText(path)
else:
self.lb_path.setText("")
#.........这里部分代码省略.........