本文整理汇总了Python中PyQt4.QtGui.QDirModel.columnCount方法的典型用法代码示例。如果您正苦于以下问题:Python QDirModel.columnCount方法的具体用法?Python QDirModel.columnCount怎么用?Python QDirModel.columnCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QDirModel
的用法示例。
在下文中一共展示了QDirModel.columnCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FileSystemBrowser
# 需要导入模块: from PyQt4.QtGui import QDirModel [as 别名]
# 或者: from PyQt4.QtGui.QDirModel import columnCount [as 别名]
class FileSystemBrowser(QTreeView):
"""simple file system browser"""
def __init__(self):
QTreeView.__init__(self)
self.model = QDirModel()
self.setModel(self.model)
self.setSortingEnabled(True)
self.setAlternatingRowColors(True)
self.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.setAutoExpandDelay(500)
i = self.model.index(os.getcwd())
self.scrollTo(i)
self.expand(i)
self.setCurrentIndex(i)
for i in range(self.model.columnCount()):
self.resizeColumnToContents(i)
self.connect(self, SIGNAL("doubleClicked(QModelIndex)"), self.itemAction)
self.connect(self, SIGNAL("customContextMenuRequested(QPoint)"), self.showContextMenu)
def itemAction(self, mi):
"""default action (on doubleclick) for item at model index mi"""
fi = self.model.fileInfo(mi)
if self.model.isDir(mi):
return
path = str(fi.absoluteFilePath())
if not SimuVis4.Globals.fileTypeActions.openFile(path):
self.openExternal(path)
def showContextMenu(self, pos):
"""show context menu for item at pos"""
mi = self.indexAt(pos)
fi = self.model.fileInfo(mi)
m = QMenu()
self.path = str(fi.absoluteFilePath())
if self.model.isDir(mi):
m.addAction(QCoreApplication.translate('DataBrowser', 'Refresh'),
lambda x=mi: self.model.refresh(x))
else:
for a in SimuVis4.Globals.fileTypeActions.getActions(self.path):
# this is weird, ... but it works
m.addAction(a[0], lambda x=a[1]: x(self.path))
m.addSeparator()
m.addAction(QCoreApplication.translate('DataBrowser', 'Open external'),
self.openExternal)
a = m.exec_(self.mapToGlobal(pos))
def openExternal(self, path=None):
if not path:
path = self.path
QDesktopServices.openUrl(QUrl.fromLocalFile(path))
示例2: FileSystemBrowser
# 需要导入模块: from PyQt4.QtGui import QDirModel [as 别名]
# 或者: from PyQt4.QtGui.QDirModel import columnCount [as 别名]
class FileSystemBrowser(QTreeView):
"""simple file system browser, no actions yet"""
def __init__(self):
QTreeView.__init__(self)
self.model = QDirModel()
self.setModel(self.model)
self.setSortingEnabled(True)
i = self.model.index(os.getcwd())
self.scrollTo(i)
self.expand(i)
self.setCurrentIndex(i)
for i in range(self.model.columnCount()):
self.resizeColumnToContents(i)