Results 1 to 3 of 3

Thread: Hide QT Control at Runtime

  1. #1
    Join Date
    Oct 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Smile Hide QT Control at Runtime

    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).

    So:

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

    Thanks!

  2. #2
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Hide QT Control at Runtime

    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

    ex:
    Qt Code:
    1. foreach(QObject obj, parent.children()
    2. {
    3. QPushButton* pb = dynamic_cast<QPushButton*> (obj);
    4. if(pb){
    5. //you have handle
    6. }
    7.  
    8. //if you already set object name like obj.setObjectName(QString("my pushButton"));
    9. if(QString("my pushButton") == obj.objectName()){
    10. //you have handle
    11. }
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 
    Thanks :-)

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Hide QT Control at Runtime

    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.
    Last edited by d_stranz; 7th October 2015 at 04:14.

Similar Threads

  1. Replies: 1
    Last Post: 25th September 2010, 08:20
  2. Control box hide
    By maider in forum Qt Programming
    Replies: 2
    Last Post: 16th November 2009, 14:03
  3. ActiveQt - How can I hide an ActiveX control ?
    By John82 in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2009, 22:12
  4. How to hide dotted lines around the focused control?
    By gimel in forum Qt Programming
    Replies: 3
    Last Post: 6th November 2008, 07:09
  5. Simple frame control doesn't resize when I hide()
    By MrGarbage in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2007, 22:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.