How to set focus in a LineEdit in qtScript?

I’m using the incredibly handy FindAndReplace.js script available here:

I’m making a quick modification to have some text already filled out for the find section (“asdf” based on the super helpful suggestions from Stylus Rumble):

What I’d like to do is make sure the mouse focus is in the Replace Text Field as soon as the UI is brought up so I can basically click the button, type what I want, and hit enter.

does anyone know how to set the focus in a LineEdit field?


Hi !

With a Dialog that came from the Harmony scripting reference is not doable. Because the setFocus is not exposed.

Here I did the script you talked about and I add a line that set the focus on the second lineEdit.

You will see the line it’s pretty simple.

So here, instead of using the Dialog, I created it myself from scratch. Means that you can control everything.
You can also go further, imagine selecting your nodes, launching the script, you type what you want because you are already in the good lineEdit, and then with an event listener, you can validate by pressing Enter or whateverelse.
It would be : select, type, enter.

Boom !

Hope it helps.


Hah! holy crap, that’s awesome! thanks so much eAthis!

I had to comment out the line:


because it was creating the window on my other monitor, and I couldn’t move it… heh :slight_smile:

But this is awesome!

Another quick question - with this is there a way to make hitting the ENTER key execute the findAndReplace function? This way you don’t have to move your mouse at all, you just hit it, type, and done!

thanks so much!

Hi again !

Yep ! Just change the first line of the createWidget function with this :

var own = new QDialog();

Instead of using a widget, you’ll use a dialog. Their buttons already have some “responders”, so if you hit enter, it should validate it.

Hope it helps.


That’s absolutely amazing - thank you eAthis!

I’ve now gotten a super fast find/replace and also rename dialog that I can use to work crazy quickly.

Thank you! :slight_smile:

Glad you’re happy !

We should share it.

Topic solved !



Heya! Sorry it took me so long to do this, but I’ve put up a github repo with some of the scripts I’ve been working on - including the one you helped with! :slight_smile:

Awesome !

Let’s share them with the world !

Thanks for the acknowledgement.



Thank you, eAthis! Your trick with the UI has really helped me out tremendously. :wink:


Fantastic job eAthis, great support to the community.

Best Regards,

Technical Support Specialist
Toon Boom Animation


I just stumbled upon this thread and this is pretty fascinating! I’ve used an external dialog file made with QT Creator before as well as used widgets but never made a dialog from scratch just out of code. That’s pretty brilliant!

I’m trying to do something a bit complicated and I haven’t found the answer yet. Do you know if there is a way for the dialog to not set the focus but detect it when it comes back to the dialog?

In other words, I have this dialog that sits on top of the interface, allowing for some actions. What I would like is to be able to change my selection in toonboom and when I go back to my dialog to perform a new action, for it to display some info about the new selection. I am currently using a button to do that, but it’s not so clean. I would like to detect when the dialog comes back into focus and run an update function at that time. Any idea if this is possible? I’ve looked for a focus related signal to connect my fonction to but so far no luck.

Thank you in advance, and to jasonschleifer as well for his repo and starting this great conversation!


I guess you talk about a selection in the node view ? Anyway, it doesn’t change anything.

Well, I’m pretty sure there is something to do . I’m not with a computer these days but I’ll take a look at it next year :wink:

Maybe something with “loose focus” or something like that.

Stay tuned !



So I managed to make it work.
When I do a selection in the node view then launch the script, the label in the QWidget shows me how many selected nodes I have.
Then if I lose focus, select more or less nodes then click on the QWidget to set the focus back on it, it automatically updates the label and shows me the number of selected nodes.

So I guess it’s what you wanted.
Here is the link to download the script.

Feel free to ask more.

Hope it helps.


That’s incredible! Thank you so much.

I’m learning an awful lot about QTUI thanks to you!

I hope I can make my scripts available in the future as a way to say thanks!

You should make a developers blog about the intricacies of toonboom scripting, that would be so interesting. Kind of like what Ajar Productions was to Flash scripting back in the day!