View Full Version : Hide QT Control at Runtime

7th October 2015, 00:25
If there a way to get a handle to QT objects at runtime. For example in Windows you can issue "FindWindow" and get a handle to an object, then call SetWindowText to change text, ShowWindow to hide the window, etc. You can use Spy++ to query the objects.

I need to do the same for a QT application which I did not write (i.e. at runtime).


1. Get Handle to the button.
2. Send hide command


7th October 2015, 04:56
you can use
const QObjectList & QObject::children ()

which returns list of objects and the you can use dynamic cast to identify the item. //you can use objectName() also for identifying particular object


foreach(QObject obj, parent.children()
QPushButton* pb = dynamic_cast<QPushButton*> (obj);
//you have handle

//if you already set object name like obj.setObjectName(QString("my pushButton"));
if(QString("my pushButton") == obj.objectName()){
//you have handle


7th October 2015, 05:08
Or you can simply create a member variable and store the pointer to the QWidget in that. If you think about the design before you write the application, it should rarely if ever be necessary to search for a pointer to a widget after the fact. Even if you use Qt Designer, you can still retrieve the desired pointer via the "ui" instance and save a copy of the pointer in a member variable for easier access.

And searching for a pointer to a button in a running application that you did not write probably will not work using prasad_N's method, because for one thing, you don't necessarily know that it is a Qt-based application, and for another, you have no idea what the names of the widgets are. At best, you can use the Windows tools to get the window handle (if you can discover which handle actually corresponds to the button you are interested in), create a QWidget / QWindow to wrap it, the call hide. If you can get the Windows handle, you might as well just send it the appropriate WM_ message using the Windows API.