How can we associate an QWidget object with QRect object so that whenever i want to know Qrect value i can get from Qwidget object?
-
There are many different options for what could go wrong, but you need to do your own debugging. There is no way can do that for you, especially if you don't provide us with the code you wrote for it.
-
This can only be answered if we see more code.
Dynamic properties in general work, I use them from time to time. -
[quote author="Gerolf" date="1322040896"]This can only be answered if we see more code.
Dynamic properties in general work, I use them from time to time.[/quote]I find it save to assume that Qt's functions work, unless I have some very strong proof they don't. That means that I assume the problem is in my code, not in Qt, and that works out reasonably well in debugging :-)
-
Sorry, actually one mistake was there in my code now i am getting the proper output.One thing still i want to ask in the function in which i am using the following function
@QRect r = myWidget->property("magicRectProperty").toRect();@
i have only mywidget object not the string "magicRectproperty". so how can i get the rect using only object not the string? -
The string is always the same, chosen by you - like a variable.
-
[quote author="Lukas Geyer" date="1322042786"]The string is always the same, chosen by you. [/quote]
No my problem is the function in which i am using setproperty and property both are not in the same scope . So, when i want to retrieve the property of any object i dont know the string in that scope.so how i will get the rect?
@QRect r = myWidget->property( ? ).toRect();@ -
You do know the string because you have chosen it.
If you assign a dynamic property of a QObject using setProperty("fancyPropertyName", fancyValue) it will be accessible anywhere in your application using property("fancyPropertyName"). Dynamic properties are just like member variables, but declared at runtime, not compile time.
-
Lukas is totally right. You know the string in the same way that you know the name of class methods: you implemented them. On the other hand you can list them if you really want. See the QObject::dynamicPropertyNames() method.
-
[quote author="Lukas Geyer" date="1322043483"]You do know the string because you have chosen it.
If you assign a dynamic property of a QObject using setProperty("fancyPropertyName", fancyValue) it will be accessible anywhere in your application using property("fancyPropertyName"). Dynamic properties are just like member variables, but declared at runtime, not compile time.[/quote]
[quote author="Lukas Geyer" date="1322043483"]You do know the string because you have chosen it.
If you assign a dynamic property of a QObject using setProperty("fancyPropertyName", fancyValue) it will be accessible anywhere in your application using property("fancyPropertyName"). Dynamic properties are just like member variables, but declared at runtime, not compile time.[/quote]
Can you please see this
@
main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
ofi_vc_gui_tooltip tp(&w);
QPushButton *button1 = new QPushButton(&w);
QSlider *slider = new QSlider(&w);
button1->setProperty ("button1",QRect(0,0,120,150));
slider->setProperty ("slider",QRect(0,0,120,150));
tp.add(button1);
tp.add(slider);
..................................................
..................................................
}customclass.cpp
void customclass::add (QWidget *widget)
{
object = widget;
qDebug ()<<object->property ( ? ).toRect ();
// Here object can be anyone.}
@
Here object in custom class always different then how can i get the rect? -
Why would you give the property the name of the object itself? What is that supposed to mean? Why not choose the same name in both cases, and choose a name that makes sense, like, "sensitiveRect" or something like that. Note that because the object instances are different, they properties will not overwrite each other or something like that. slider and button1 will just both have a property called "sensitiveRect".
-
Now i got thanks