Issue
I'm trying to find a way of selecting QtGui.QTreeWidget.QTreeWidgetItem.text(1) with the cursor.
if column == 1:
# Makes Row editable
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
# Select item to edit
Xitem = self.treewidget.editItem(item, column)
# Makes Row uneditable
item.setFlags(item.flags() & ~QtCore.Qt.ItemIsEditable)
I know that, by default, all the text will be selected. However, because I'm enabling editing then disabling editing is results with the text being unselected.
Why are you enabling and disabling edibility?
I have it set up so that you can only edit the text of 1 column, out of several. However, simply turning on ItemIsEditable will make all columns editable, i just wanted the one specific column, so i immediately have to disable it again.
Knock on effect, it deselects the text in the desired column. I can still edit it, it's just deselected.
So i want to ctrl+a selected all. I've been trying to work out how to do this for a while, but am getting no where.
Methods for getting my desired results would be running the ctrl+a hotkey through python code, or working out how to get the QTextCursor stuff to work with the QTreeWidgetItem.
editor = QtGui.QTextEdit(self.treewidget)
cursor = editor.textCursor()
cursor.movePosition(QtGui.QTextCursor.Start, QtGui.QTextCursor.KeepAnchor)
editor.setTextCursor(cursor)
I feel like i'm close, but am just missing something here :/
Solution
Ok, I found a solution to this, although I couldn't workout how to select all text I was able to clean up my script to get the desired result:
def checkEditFUNC(self, item, column):
'''
Allows editing of certain items in the table
:param item: item name
:param column: Column number
'''
# To allow editing only in column 1 and 2
if column == 1:
# Makes Row editable
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
else:
item.setFlags(item.flags() & ~QtCore.Qt.ItemIsEditable)
Answered By - Adam Sirrelle
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.