本文整理汇总了Python中PySide.QtGui.QTableView.sortByColumn方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.sortByColumn方法的具体用法?Python QTableView.sortByColumn怎么用?Python QTableView.sortByColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTableView
的用法示例。
在下文中一共展示了QTableView.sortByColumn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: skillsWindow
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import sortByColumn [as 别名]
class skillsWindow(QDialog):
def __init__(self, dataModel, oberTablo):
QDialog.__init__(self)
self.setWindowTitle('All Skills')
self.setWindowIcon(QIcon('elance.ico'))
self.oberTablo = oberTablo
#create & configure tablewiew
self.table_view = QTableView()
self.table_view.setModel(dataModel)
self.table_view.setSortingEnabled(True)
self.table_view.sortByColumn(1, Qt.DescendingOrder)
self.table_view.resizeColumnsToContents()
self.table_view.resizeRowsToContents()
#http://stackoverflow.com/questions/7189305/set-optimal-size-of-a-dialog-window-containing-a-tablewidget
#http://stackoverflow.com/questions/8766633/how-to-determine-the-correct-size-of-a-qtablewidget
w = 0
w += self.table_view.contentsMargins().left() +\
self.table_view.contentsMargins().right() +\
self.table_view.verticalHeader().width()
w += qApp.style().pixelMetric(QStyle.PM_ScrollBarExtent)
for i in range(len(self.table_view.model().header)):
w += self.table_view.columnWidth(i)
self.table_view.horizontalHeader().setStretchLastSection(True)
self.table_view.setMinimumWidth(w)
# create two buttons
self.findEntries = QPushButton('Find entries')
self.findEntries.clicked.connect(self.ApplyFilterToMainList)
self.cancel = QPushButton('Cancel')
self.cancel.clicked.connect(self.winClose)
self.mainLayout = QGridLayout()
self.mainLayout.addWidget(self.table_view, 0,0,1,3)
self.mainLayout.addWidget(self.findEntries, 1,0)
self.mainLayout.addWidget(self.cancel, 1,2)
self.setLayout(self.mainLayout)
self.show()
def ApplyFilterToMainList(self):
selection = self.table_view.selectionModel().selection()
skills = []
for selRange in selection:
for index in selRange.indexes():
skill = index.model().data(index, Qt.DisplayRole)
skills.append(skill)
self.oberTablo.model().emit(SIGNAL("modelAboutToBeReset()"))
self.oberTablo.model().criteria = {'Skills':skills}
self.oberTablo.model().emit(SIGNAL("modelReset()"))
self.close()
def winClose(self):
self.close()
示例2: MainWindow
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import sortByColumn [as 别名]
class MainWindow(QMainWindow):
def __init__(self, datta):
QMainWindow.__init__(self)
self.setWindowTitle('Project Parser')
appIcon = QIcon('search.png')
self.setWindowIcon(appIcon)
self.viewPortBL = QDesktopWidget().availableGeometry().topLeft()
self.viewPortTR = QDesktopWidget().availableGeometry().bottomRight()
self.margin = int(QDesktopWidget().availableGeometry().width()*0.1/2)
self.shirina = QDesktopWidget().availableGeometry().width() - self.margin*2
self.visota = QDesktopWidget().availableGeometry().height() - self.margin*2
self.setGeometry(self.viewPortBL.x() + self.margin, self.viewPortBL.y() + self.margin,
self.shirina, self.visota)
# statusbar
self.myStatusBar = QStatusBar()
self.setStatusBar(self.myStatusBar)
#lower long layout
self.lowerLong = QFrame()
self.detailsLabel = QLabel()
self.skillsLabel = QLabel()
self.urlLabel = QLabel()
self.locationLabel = QLabel()
self.skillsLabel.setText('skills')
self.detailsLabel.setWordWrap(True)
self.la = QVBoxLayout()
self.la.addWidget(self.detailsLabel)
self.la.addWidget(self.skillsLabel)
self.la.addWidget(self.urlLabel)
self.la.addWidget(self.locationLabel)
self.lowerLong.setLayout(self.la)
# table
self.source_model = MyTableModel(self, datta, ['Id', 'Date', 'Title'])
self.proxy_model = myTableProxy(self)
self.proxy_model.setSourceModel(self.source_model)
self.proxy_model.setDynamicSortFilter(True)
self.table_view = QTableView()
self.table_view.setModel(self.proxy_model)
self.table_view.setAlternatingRowColors(True)
self.table_view.resizeColumnsToContents()
self.table_view.resizeRowsToContents()
self.table_view.horizontalHeader().setStretchLastSection(True)
self.table_view.setSortingEnabled(True)
self.table_view.sortByColumn(2, Qt.AscendingOrder)
# events
self.selection = self.table_view.selectionModel()
self.selection.selectionChanged.connect(self.handleSelectionChanged)
#DO NOT use CreateIndex() method, use index()
index = self.proxy_model.index(0,0)
self.selection.select(index, QItemSelectionModel.Select)
self.upperLong = self.table_view
# right side widgets
self.right = QFrame()
self.la1 = QVBoxLayout()
self.btnDownload = QPushButton('Download data')
self.btnDownload.clicked.connect(self.download)
self.myButton = QPushButton('Show Skillls')
self.myButton.clicked.connect(self.showAllSkills)
self.btnSearchByWord = QPushButton('Search by word(s)')
self.btnSearchByWord.clicked.connect(self.onSearchByWord)
self.btnResetFilter= QPushButton('Discard Filter')
self.btnResetFilter.clicked.connect(self.discardFilter)
self.btnCopyURL = QPushButton('URL to Clipboard')
self.btnCopyURL.clicked.connect(self.copyToClipboard)
self.btnExit = QPushButton('Exit')
self.btnExit.clicked.connect(lambda: sys.exit())
self.dateTimeStamp = QLabel()
self.la1.addWidget(self.btnDownload)
self.la1.addSpacing(10)
self.la1.addWidget(self.myButton)
self.la1.addSpacing(10)
self.la1.addWidget(self.btnSearchByWord)
self.la1.addSpacing(10)
self.la1.addWidget(self.btnResetFilter)
self.la1.addSpacing(10)
self.la1.addWidget(self.btnCopyURL)
self.la1.addSpacing(70)
self.la1.addWidget(self.btnExit)
self.la1.addStretch(stretch=0)
self.la1.addWidget(self.dateTimeStamp)
self.right.setLayout(self.la1)
self.right.setFrameShape(QFrame.StyledPanel)
# splitters
self.horiSplit = QSplitter(Qt.Vertical)
self.horiSplit.addWidget(self.upperLong)
self.horiSplit.addWidget(self.lowerLong)
self.horiSplit.setSizes([self.visota/2, self.visota/2])
self.vertiSplit = QSplitter(Qt.Horizontal)
self.vertiSplit.addWidget(self.horiSplit)
self.vertiSplit.addWidget(self.right)
self.vertiSplit.setSizes([self.shirina*3/4, self.shirina*1/4])
self.setCentralWidget(self.vertiSplit)
self.settings = QSettings('elance.ini', QSettings.IniFormat)
self.settings.beginGroup('DATE_STAMP')
#.........这里部分代码省略.........