PDA

View Full Version : how to access and control QLabel by ObjectName?



lamp
3rd November 2010, 18:14
Hi

how to access and conrol QLable by ObjectName?

My code



void MakeAndShow_Objects::AnimatedObj_Show(QString Animated_objname)
{
Animated_label = new QLabel(this);
Animated_label->setObjectName(Animated_objname);

movie = new QMovie(Animated_label);
movie->setObjectName(Animated_objname+"mv");

Animated_label->setGeometry(QString(ValuePostion_List[0]).toInt(),QString(ValuePostion_List[1]).toInt(),drawW,drawH);
movie->setFileName(rsource+"Multimedia_Objects/Pic"+All_List.value(Animated_objname));
Animated_label->setScaledContents(true);
Animated_label->setMovie(movie);
movie->start();
qDebug()<<"animated"<<Animated_label->objectName();
Animated_label->show();
}


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 !

tbscope
4th November 2010, 04:35
What is "this" ?

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

lamp
4th November 2010, 09:04
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")

tbscope
4th November 2010, 09:05
What was your question?

lamp
4th November 2010, 09:31
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.