Copy and paste editbox

Started by roccio, 07 March 2017, 14:25:41

roccio

Hello,
sorry if this has been already discussed, I have used the search function but have not found anything.
My problem is to have an editbox where I can paste the string from the clipboard.

Any advice?

texus

TGUI has an internal clipboard that allows copying and pasting from one edit box to the other by just selecting text and pressing ctrl+c and ctrl+v.
On windows the system clipboard is also accessed so that you can copy things from other applications. On linux and mac accessing the system clipboard it is currently not supported so you can't paste things other than what you copied in tgui.

roccio


roccio

Sorry again, but I am only able to copy and paste from tgui editboxes. If I copy data from an externat text editor (for example) the paste is not performed on editbox. Is there something that I must enable?

texus

#4
It should work out of the box, but it hasn't been tested for a long time (only briefly when the feature was added).

First of all make sure you are copying plain text data only by copying some text from notepad. Although I doubt it is the case, I think it is technically possible for a program to only put the formatted text in the clipboard without including the plain text.

What OS and compiler are you using?
Edit: could you also show a minimal example code that I can just copy-paste to test with?

roccio

I have made a simple test application, but it works perfectly, so I need to check in my code.
Btw running on Windows10 with Visual studio 2015 and tgui 0.7.3

texus

Do you set an sf::RendererWindow to the Gui in your code?

I realized that the clipboard won't work if you draw to an sf::RenderTexture as it needs a window to work.

roccio

Yes, I set a RenderWindow. I noted that the "internal" tgui clipboard works, but not the windows one. So I can't even copy a string from the tgui editbox and paste in notepad.

texus

The gui should take care of attaching the system clipboard when you pass an sf::RenderWindow as parameter to gui.setWindow.
The only two reasons why this would not be done that I can think of is when you run the code on linux or mac or when you set a RenderTexture instead of a RenderWindow. But neither should be the case here.

You may want to try calling the following function in your own code and see if it helps:
Code (cpp) Select
tgui::Clipboard::setWindowHandle(yourSfmlRenderWindow.getSystemHandle());

roccio

Adding

tgui::Clipboard::setWindowHandle(gui.getWindowHandle());

make it works.

Thank you very much.