Clicking in QTreeWidget item while already editing reopens the editor.
-
This is a very simple problem that is easy to repro. It might a bug, but I'll try to describe what I'm looking for first.
I have a QTreeWidget and I want the following standard behavior:
Single click an item selects the item.
Single click an already selected item allows for editing the item.
Double click takes other special action.If I single click an already selected selected QTreeWidgetItem, the line edit opens as it should.
However, if I click inside that line edit, it closes, then re-opens the line editor again with all of the text selected, which is not what I want.
If I click inside of an already opened line edit, it should remain open, and de-select any selected text. This is standard behavior for edit controls.
This seems like it would be very common, standard behavior for most usage of QTreeWidget, so I'm hesitant to call it a bug. But I've tried everything I can possibly think of an nothing will work. Can anyone shed some light? Thanks.
Using a custom build of Qt5 on Windows 7, x64.
-
[quote author="mfeemster" date="1371439525"]
This seems like it would be very common, standard behavior for most usage of QTreeWidget, so I'm hesitant to call it a bug.[/quote]I wouldn't say that this is default behavior in good GUI design manners.
But without posting any of your code nobody will be able to help you...
Especially the part where you start editing on an index on the click of an already selected index will be interesting. -
Perhaps I wasn't clear. I am saying that the current Qt behavior for the edit trigger 'SelectedClicked' is not consistent with the standard behavior of edit controls.
For an example of the standard behavior I am after, try renaming a file on your system by clicking on it, then clicking again. An edit box will open up. When you click in that edit box, it positions the cursor for you to type. That is what I'm after, yet Qt does something quite different.
Repro steps and code:
- Place a tree view with one column on your window via Qt Designer and name it TestTree.
- For the edit triggers, set 'SelectedClicked', and uncheck the others.
- Construct some items with the following code and run.
- Click one of the child items, then click it again. An edit box will open up. When you click in the edit box, instead of positioning the cursor, it closes it, re-opens it, then selects all of the text. That is not what I want it to do.
[CODE]
QTreeWidget* tree = ui.TestTree;
QTreeWidgetItem* topItem = new QTreeWidgetItem(tree);
topItem->setText(0, "top text");QTreeWidgetItem* childItem1 = new QTreeWidgetItem(topItem);
childItem1->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
childItem1->setText(0, "child text 1");QTreeWidgetItem* childItem2 = new QTreeWidgetItem(topItem);
childItem2->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
childItem2->setText(0, "child text 2");
[/CODE]Any insight is much appreciated. Thanks.
-
i can't reproduce the issue you described.
When an item is opened for editing the editor gets the focus set immediately. If it looses the focus it will get closed. Maybe you change the focus somewhere?
Or there is some other code which you aren't posted which causes this misbehavior.This code works as expected:
@
QTreeWidget* tree = new QTreeWidget;
tree->setEditTriggers( QAbstractItemView::SelectedClicked );QTreeWidgetItem* topItem = new QTreeWidgetItem(tree); topItem->setText(0, "top text"); QTreeWidgetItem* childItem1 = new QTreeWidgetItem(topItem); childItem1->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable); childItem1->setText(0, "child text 1"); QTreeWidgetItem* childItem2 = new QTreeWidgetItem(topItem); childItem2->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable); childItem2->setText(0, "child text 2");
@
-
[quote author="raven-worx" date="1371536186"]If it looses the focus it will get closed. Maybe you change the focus somewhere?
[/quote]No, I don't change or lose the focus. In order to repro:
Click the item to select it.
Click the item again to edit.
Do not move the mouse at all, so the editor remains open and has focus.
Click the editor again. It closes, then opens again with all of the text selected.If it still doesn't repro for you, I'll assume I pulled code that has a bug in it. I'll try pulling fresh from qt5stable to see if perhaps it's been fixed. Let me know, thanks.
-
yes... still not reproducible ;)
-
Thanks for checking on that. I will do a fresh pull from qt5stable, rebuild and see where it gets me. I'll post here to confirm if it's fixed.
Edit: It was fixed. Thanks.