Created
March 8, 2017 14:14
-
-
Save BigRoy/6eb92c6b0a035c2cfdc492964e6dac7a to your computer and use it in GitHub Desktop.
Set QColumnView selection (and update the columns)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
from Qt import QtWidgets, QtCore, QtGui | |
def main(): | |
app = QtWidgets.QApplication(sys.argv) | |
path = r"C:\test\subfolder\file.txt" | |
root_path = os.path.dirname(os.path.dirname(path)) | |
model = QtWidgets.QFileSystemModel() | |
view = QtWidgets.QColumnView() | |
view.setModel(model) | |
# Set root | |
model.setRootPath(root_path) | |
root_index = model.index(root_path) | |
view.setRootIndex(root_index) | |
# Problem #1: | |
# Setting the current index does set up the horizontal scrollbar (as if it works) | |
# but it doesn't actually select anything nor do the columns show up on the right side | |
index = model.index(path) | |
assert index.isValid() | |
view.setCurrentIndex(index) | |
# Problem #2: | |
# Setting the selection doesn't seem to do anything either. | |
selection = view.selectionModel() | |
selection.select(index, QtGui.QItemSelectionModel.Rows) | |
view.show() | |
sys.exit(app.exec_()) | |
if __name__ == '__main__': | |
main() |
This works for me as well.
That one does work, yes. Are you able to get it to work when "highlighting" something in columns nested down? Basically expanding the columns op to that selection. Even with combinations of scroll to and alike I'm unable to get that to work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works for me as well.