Planned maintenance: From Sunday 8th December 10:00 CET there will be changes to try and solve the caching issues that have been experienced. If anyone has a problem connecting after this period then please PM @AndyS or any of the moderators.
Override default copy/paste from QTextEdit
zespy last edited by zespy
I have a main window that has a
QAction(copy, cut and paste), mapped on the default shortcuts (respectively ctrl+c, ctrl+x and ctrl+v). The goal of the actions is to copy/paste the contents of the
QTextEdit, but with extra-work (the contents is copied as
QTextEditalready implements its own copy/paste functions, with the same shortcuts. When I hit ctrl+c, it is always the
QTextEditcopy function that is used, instead of mine (so there is no
application/jsonin the clipboard...).
How can I change this behavior, and use my functions instead? I saw that there is a QEvent::ShortcutOverride event, but I don't know how to use it... can I use it in an QObject::eventFilter() function? Or should I inherit from QTextEdit and override its QWidget::keyPressEvent() method?
The best for me would be to totally disconnect the default copy/paste from the
QTextEditand use only mine. I can inherit and try to mess up with the class (but how?), but the best solution would be that it works even with polymorphism (but the slots are not virtual).
Thanks for your help :)
edit: QTextEdit::createMimeDataFromSelection() is not an option for me as I also have a
QLineEditand I'd like the same behavior with it (to not use its default copy/paste functions).
You can use
QTextEdit::actionsto retrieve the list of actions already with the widget, then you can use
QTextEdit::addActionto remove the old one and add your custom ones
zespy last edited by
Bien vu !
I missed this function during my search... I'll try tomorrow and update this thread accordingly.
zespy last edited by
Unfortunately, it doesn't seems to work...
actions()returns me an empty list.
I think I'll go for
QTextEdit::createMimeDataFromSelection()because otherwise I won't be able to deal with drag & drop (I didn't think about it :/ )