PDA

View Full Version : Help about qt and search box



kmthrong
31st July 2015, 12:54
Hi I'm a new user of QT soI made a script for maya with QT designer so far It has so many buttons with so many names on it as you can see:
http://oi62.tinypic.com/16ht3zc.jpg
Ok I wanna make a search box that when I write into it things it finds buttons for example if I write lip it goes and finds the first button that has this name on it So How can I do that plz somebody explain about it.I used the 2 files:
expr.py
expr.ui
Okay so I don't know anything about .cpp files or QML or the others Help plz and explain it with picture or video if you can TNX :|

ChrisW67
1st August 2015, 06:13
Assuming you want a partial name match.

In pseudo-code...


When the user presses your Search button with queryText in a line edit:
Use QObject::findChildren() to locate all QPushButton children of the scroll area
Iterate over all the QPushButton children:
If child text().startsWith(queryText)
scrollArea.ensureWidgetVisible(child)
exit loop

You could use toLower() to do case-insensitive query, or contains() instead of startsWith().

For an exact name match findChildren() can do the whole search for you.

kmthrong
1st August 2015, 10:00
Tnx for your reply dude but I didn't get where should I use it in .py file or .ui where exacly can you show by a picture ?

anda_skoa
1st August 2015, 12:50
The .ui file is a just an XML document describing the UI, it does not contain any code.

The .py file, on the other hand, is a Python source file, it does contain code.

Cheers,
_

kmthrong
2nd August 2015, 00:02
TNX for reply so

In pseudo-code...
Qt Code: Switch view
When the user presses your Search button with queryText in a line edit:
Use QObject::findChildren() to locate all QPushButton children of the scroll area
Iterate over all the QPushButton children:
If child text().startsWith(queryText)
scrollArea.ensureWidgetVisible(child)
exit loop

Where is In pseudo-code to use this code in??if it isn't py and ui file so what is it? it's in QT itself?WHere if you show me by picture I'll be really thankful.

anda_skoa
2nd August 2015, 12:12
Where is In pseudo-code to use this code in??

As I explained, the .py file holds the program code.



if it isn't py and ui file so what is it?

It is Pseudo Code, a human readable description of steps that are necessary to achieve a desired goal.
The idea is to convey the procedure without having to know the target language in detail.

In your case the target language seems to be Python, you need to write the respective Python code that performs the steps laid out in the Pseudo Code.

Cheers,
_

kmthrong
24th August 2015, 12:56
TNX I tried to understand but I couldn't get anything because I'm a beginner would you plz upload a video I didn't get your mean !
This is the py file:
http://up2www.com/uploads/453fexpr22.rar

TNX I tried to understand but I couldn't get anything because I'm a beginner would you plz upload a video I didn't get your mean !
This is the py file:
http://up2www.com/uploads/453fexpr22.rar