Results 1 to 5 of 5

Thread: how to access and control QLabel by ObjectName?

  1. #1
    Join Date
    Oct 2010
    Location
    Iran
    Posts
    27
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question how to access and control QLabel by ObjectName?

    Hi

    how to access and conrol QLable by ObjectName?

    My code

    Qt Code:
    1. void MakeAndShow_Objects::AnimatedObj_Show(QString Animated_objname)
    2. {
    3. Animated_label = new QLabel(this);
    4. Animated_label->[B]setObjectName(Animated_objname);[/B]
    5.  
    6. movie = new QMovie(Animated_label);
    7. movie->setObjectName(Animated_objname+"mv");
    8.  
    9. Animated_label->setGeometry(QString(ValuePostion_List[0]).toInt(),QString(ValuePostion_List[1]).toInt(),drawW,drawH);
    10. movie->setFileName(rsource+"Multimedia_Objects/Pic"+All_List.value(Animated_objname));
    11. Animated_label->setScaledContents(true);
    12. Animated_label->setMovie(movie);
    13. movie->start();
    14. qDebug()<<"animated"<<Animated_label->objectName();
    15. Animated_label->show();
    16. }
    To copy to clipboard, switch view to plain text mode 

    using This code and return true

    this->findChild<QLabel *>(Animated_objname)

    After big search not found any useful think and unknown to close, hide or ... QLable by objectname !

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: how to access and control QLabel by ObjectName?

    What is "this" ?

    You should use the top most object to find a child. In most cases that's the application object.

  3. #3
    Join Date
    Oct 2010
    Location
    Iran
    Posts
    27
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how to access and control QLabel by ObjectName?

    Quote Originally Posted by tbscope View Post
    What is "this" ?

    You should use the top most object to find a child. In most cases that's the application object.
    'this' is object class

    and code
    this->findChild<QLabel *>(Animated_objname)
    return:
    QLabel(0xa3d99b0, name = "mygif")

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: how to access and control QLabel by ObjectName?

    What was your question?

  5. #5
    Join Date
    Oct 2010
    Location
    Iran
    Posts
    27
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how to access and control QLabel by ObjectName?

    my program multi cal AnimatedObj_Show function and produce multi Qlable Animated_label by defrent objectname (see my posted cod) and I want to access this objects by objectname property.
    Last edited by lamp; 4th November 2010 at 09:47.

Similar Threads

  1. How to catch event, then objectName changed.
    By sergey_85 in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2010, 20:05
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. Replies: 6
    Last Post: 17th August 2009, 08:55
  4. findChild(ObjectName) fails?
    By Ran in forum Qt Programming
    Replies: 5
    Last Post: 21st January 2008, 06:58
  5. IO Control Mechanism (Hardware Data Access)
    By rud_1023 in forum General Programming
    Replies: 2
    Last Post: 23rd October 2006, 12:50

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.