import sys
from PyQt4 import Qt, QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(600, 400)
self.
centralwidget = QtGui.
QWidget(MainWindow
) self.
vertialLayout = QtGui.
QVBoxLayout(self.
centralwidget) self.columnView = QtGui.QColumnView(self.centralwidget)
self.columnView.setModel(self.model)
self.vertialLayout.addWidget(self.columnView)
MainWindow.setCentralWidget(self.centralwidget)
self.savedIndexes = None
self.
buttonWidget = QtGui.
QWidget(self.
centralwidget) self.
buttonLayout = QtGui.
QHBoxLayout(self.
buttonWidget) self.buttonLayout.setSpacing(0)
self.buttonLayout.setMargin(0)
self.
copyIndexButton = QtGui.
QToolButton(self.
buttonWidget) self.copyIndexButton.setText('Copy Index')
self.buttonLayout.addWidget(self.copyIndexButton)
self.
selectIndexButton = QtGui.
QToolButton(self.
buttonWidget) self.selectIndexButton.setText('Select Index')
self.buttonLayout.addWidget(self.selectIndexButton)
self.buttonLayout.addItem(self.spacer)
self.vertialLayout.addWidget(self.buttonWidget)
MainWindow.connect(self.copyIndexButton, Qt.SIGNAL('released()'), self.copyIndex)
MainWindow.connect(self.selectIndexButton, Qt.SIGNAL('released()'), self.selectIndex)
def copyIndex(self):
self.savedIndexes = self.columnView.selectionModel().selection().indexes()
def selectIndex(self):
self.
columnView.
selectionModel().
select(self.
savedIndexes[0], Qt.
QItemSelectionModel.
SelectCurrent)
if __name__ == "__main__":
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
import sys
from PyQt4 import Qt, QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(600, 400)
self.centralwidget = QtGui.QWidget(MainWindow)
self.vertialLayout = QtGui.QVBoxLayout(self.centralwidget)
self.columnView = QtGui.QColumnView(self.centralwidget)
self.model = QtGui.QDirModel()
self.columnView.setModel(self.model)
self.vertialLayout.addWidget(self.columnView)
MainWindow.setCentralWidget(self.centralwidget)
self.savedIndexes = None
self.buttonWidget = QtGui.QWidget(self.centralwidget)
self.buttonLayout = QtGui.QHBoxLayout(self.buttonWidget)
self.buttonLayout.setSpacing(0)
self.buttonLayout.setMargin(0)
self.copyIndexButton = QtGui.QToolButton(self.buttonWidget)
self.copyIndexButton.setText('Copy Index')
self.buttonLayout.addWidget(self.copyIndexButton)
self.selectIndexButton = QtGui.QToolButton(self.buttonWidget)
self.selectIndexButton.setText('Select Index')
self.buttonLayout.addWidget(self.selectIndexButton)
self.spacer = QtGui.QSpacerItem(50, 5, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.buttonLayout.addItem(self.spacer)
self.vertialLayout.addWidget(self.buttonWidget)
MainWindow.connect(self.copyIndexButton, Qt.SIGNAL('released()'), self.copyIndex)
MainWindow.connect(self.selectIndexButton, Qt.SIGNAL('released()'), self.selectIndex)
def copyIndex(self):
self.savedIndexes = self.columnView.selectionModel().selection().indexes()
def selectIndex(self):
self.columnView.selectionModel().select(self.savedIndexes[0], Qt.QItemSelectionModel.SelectCurrent)
if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks