Copying from ApplicationWindow

• Feb 15, 2025 - 07:31

I'm showing a TextArea in an ApplicationWindow with some useful text in it. Is there any way for the user to copy that text, so they could paste it somewhere else? It looks like my window can't capture the keyboard shortcut to copy; is it possible to make a button that would copy the text to the clipboard? Is there a better kind of window to use?


Comments

In reply to by michaelnorris

I can only say that i have used the 'textarea' type in several plugins (within the 'window' type, rather than 'applicationwindow', but i don't think it makes any difference), and the shortcuts Ctrl+A Ctrl+C and Ctrl+V (if we're talking about that) work perfectly. Indeed, if we are talking about Musescore 4 the only way to 'pass' customized shortcuts to the plugin is to associate them with a text box, otherwise they are captured by the program window. This wasn't the case in Musescore 3. So I imagine that the problem lies somewhere else, although I can't guess what it is...

Out of simple curiosity, i asked myself the problem of how to copy the text selected in a 'textarea' to the clipboard via a button, and i arrived at this solution:

you need to declare this two global properties:
property int inizioSel
property int fineSel

assuming the textarea id is:
id: myTextArea

the management of this event will need to be inserted in the textarea:

onSelectedTextChanged:
{
if (myTextArea.activeFocus)
{
inizioSel = myTextArea.selectionStart;
fineSel = myTextArea.selectionEnd;
}
}

the instructions in the button's onClicked event will be:

onClicked :
{
myTextArea.select(inizioSel, fineSel);
myTextArea.copy();
}

That's all. Now I'll have to decide what I can use it for...

Do you still have an unanswered question? Please log in first to post your question.