Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 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?
Forum Updated to NodeBB v4.3 + New Features

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?

Scheduled Pinned Locked Moved General and Desktop
19 Posts 4 Posters 8.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #9

    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.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #10

      This can only be answered if we see more code.
      Dynamic properties in general work, I use them from time to time.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #11

        [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 :-)

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pratik041
          wrote on last edited by
          #12

          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?

          Pratik Agrawal

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #13

            The string is always the same, chosen by you - like a variable.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pratik041
              wrote on last edited by
              #14

              [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();@

              Pratik Agrawal

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #15

                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.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #16

                  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.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pratik041
                    wrote on last edited by
                    #17

                    [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?

                    Pratik Agrawal

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #18

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

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pratik041
                        wrote on last edited by
                        #19

                        Now i got thanks

                        Pratik Agrawal

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved