Results 1 to 5 of 5

Thread: access the widget dynamically

  1. #1
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default access the widget dynamically

    hi
    im displaying many buttons dynamically in the application based on the count from the
    database.each button has name.when a query is processed a button name is received.
    so i need to highlight the corresponding button in the front end application..
    how to do ??either a cast from string to qpushbutton possible??
    or finding the buttons in the front end with the given name??
    can any one help??
    thanks in advance!!!

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: access the widget dynamically

    there are several ways... but if i understood correctly.. on creation of buttons you can use a QHash

    QHash<QString, QPushButton*> hash;
    QString name = getNameFromSomeWhere();
    QPushButton * btn = new QPushButton(name,this);
    hash.insert(name,btn);

    and so on

  3. The following user says thank you to nish for this useful post:

    mohanakrishnan (26th November 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: access the widget dynamically

    Or you can use QObject::findChild():
    Qt Code:
    1. QPushButton *button = parentWidget->findChild<QPushButton *>("button1");
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Lykurg for this useful post:

    mohanakrishnan (26th November 2009)

  6. #4
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: access the widget dynamically

    hi mrdeath
    i ll try wat u said ,and then come back..
    thanks a lot

  7. #5
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: access the widget dynamically

    hi Lykurg
    thanks a lot it worked well.
    thanksss

    qtcentre is great

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Access the subTab Widget in Main TabWidget
    By hasnatzaidi in forum Newbie
    Replies: 1
    Last Post: 2nd September 2009, 08:21
  3. Creating dock widget as tab dynamically
    By vidyadhar in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2009, 12:03
  4. Replies: 5
    Last Post: 17th June 2009, 14:01
  5. Replies: 8
    Last Post: 20th September 2007, 09:10

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.