1

My specific problem right now is relates to a roughly 4,800 line .ui file that I’ve created in Qt Designer in which I need to do some basic refactoring (renaming widgets). I convert the .ui file to a python file via pyside-uic. I’ve gone over the Qt Designer documentation enough to convince myself with 95% certainty that it is not possible to do a global find-and-replace of widget names, or parts of names, from within Qt Designer itself. For example:

Step 1) Find 'pushButton'
Step 2) Replace with 'btn'
Step 3) Result is, i.e., 'pushButtonFooBarFooBar' gets renamed 'btnFooBarFooBar'

My first hope lies in that remaining 5% uncertainty from my document search of Qt Designer. If I’ve missed something that provides this functionality I will be elated. And I will abandon looking at more elaborate solutions using scripts and/or text editors. In the big picture, had I better planned my naming scheme about 4,800 lines of code ago I wouldn’t have this problem now.

So my question, simply put, is:

Is there a global find-and-replace functionality within Qt Designer or associated Qt tools, and if so how is it invoked?

airhuff
  • 413
  • 6
  • 18
  • No, there isn't. But surely it would be quite easy to write a one-off python script to do this. It's only xml, after all. – ekhumoro Jan 13 '17 at 17:37
  • @ekhumoro, that's what I figured. I'm guessing python's xlm module would be a good starting point, I've just never used it or worked with xml much in general. It does seem like its format would be amenable to what I need to do. Is that the starting point you would suggest, reading up on python's xml module and creating a python script based off of that? – airhuff Jan 13 '17 at 18:46
  • 1
    Before I did that, I think I would just see what could be done using search and replace in a text editor. Or maybe write a script using regular expressions, if you don't know xml. – ekhumoro Jan 13 '17 at 18:56

1 Answers1

2

Is there a global find-and-replace functionality within Qt Designer or associated Qt tools, and if so how is it invoked?

No. But since XML is a text file, you are more than welcome to do a text search-and-replace in your favorite editor. E.g. using regexps replace "pushButton([a-zA-Z0-9_$]*)" with "btn$1".

Unfortunately, Qt Creator doesn't offer a regexp capture replace function, but other editors surely do.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • Hmm, when considering this solution I didn't even think about the possibility of using regular expressions. That's ignoring a pretty powerful tool on my part I guess :( This may be the easiest solution I'll find. As a side note; Unless I'm the only one who thinks this functionality would be useful, this seems like a pretty major omission from the otherwise awesome Qt Designer program. – airhuff Jan 13 '17 at 20:03
  • Qt Designer != Qt Creator :) – Kuba hasn't forgotten Monica Jan 16 '17 at 15:59
  • Ha, I didn't even catch that! – airhuff Jan 16 '17 at 19:42