QTableWidget and edit mode
-
@Vlad02
This is because you are Qt 5.6 (why such an old version??). I still think you're supposed to havevoid QTimer::singleShot(int msec, const QObject *context, Functor functor)
and I thought my lambda would match as a
Functor
? Sigh. Do you really need to stick on Qt 5.6, it's not a good idea...?You will have to try something like:
QTimer::singleShot(100, [editor]() { editor->deselect(); } );
But I suppose that gives the same error message??
You need a lambda here really to pass the
editor
in context. I never used Qt 5.6 and I don't know what is acceptable for that, maybe an [old!] expert will see and comment...? -
@JonB
No, this is work, thanks!!!But what if, for example, I need to select the text of only the currently selected cell, but at the same time put everything in edit mode? And while doing this, I want to switch between cells through the Tab key. And when you switch to a cell, so that the text is highlighted completely in it. Is it difficult to implement?
I highlighted this with the mouse, but I would like this when switching between cells via Tab -
@Vlad02 said in QTableWidget and edit mode:
I need to select the text of only the currently selected cell, but at the same time put everything in edit mode?
For that one, in
createEditor()
detect whetherindex
refers to "the currently selected cell" and do not do thesingleShot()
to clear the selection for that one.You are asking me too many questions now! I don't know what the Tab key does, I don't know whether that highlights all the content of the new cell or not, and I don't know whether you want the opposite behaviour! I have shown a possible approach using a delay timer to deselect/select in a
QLineEdit
, maybe you need something like this in your Tab case too. You will have to play. -
@Vlad02
If necessary explain exactly what you want now, because I don't understand from what you wrote. So far as I know the Tab key will move to edit the next editable field, does it do that? If then you want it to select or deselect the whole of the new cell's edit's content, I think theQLineEdit
will get some "focus" event or signal? Maybe you could put something on that to then do de/selection, if that is the issue? -
@JonB said in QTableWidget and edit mode:
Tab key will move to edit the next editable field
Yes, you're right.
Just for convenience, it would be nice, when switching to each next cell, to select all the text in it in order to write something new, and not erase the old one and then write down the new one, that's what I'm talking about. And in the previous cell, just the new text remains and that's it, without any selections
P.S. Sorry for lengthy responses, I can write every 10 minutes :)
-
@Vlad02
If I understand what you want (still not sure). https://stackoverflow.com/questions/2804115/how-to-connect-focus-event-from-qlineedit shows to subclassQLineEdit
in order to override itsfocusIn
/OutEvent
s and emit a signal for them. Which you could attach a slot to to do the samedeselect
/selectAll()
principle as in the timer. Is that what you are looking to do?