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. Finding object from different object of the same class

Finding object from different object of the same class

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 1.8k 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.
  • T Offline
    T Offline
    tesmai4
    wrote on last edited by
    #1

    I have sub-classed QWidget class and named it MYQWidget.
    I added 4 QWidget in my interface and promoted those QWidget from to my class MyWidget.

    I need to change background color of each widget. How can I identify an object and perform a the drawing in different colors or how can I do this?

    Regards,

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      There are several possibilities. You can e.g. have a Q_PROPERTY with that color and set it from the editor.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tesmai4
        wrote on last edited by
        #3

        Thanks for your answer. It is not clear to me. Could you please post a small example?

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NeenaN
          wrote on last edited by
          #4

          This might help please check the link
          http://www.informit.com/articles/article.aspx?p=1405227

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Soraltan
            wrote on last edited by
            #5

            Hi,

            is your question actually how you can set the background colour of a QWidget(-subclass)? Because the thread title seems to be pointing more in the direction, how you could find all instances of you class, so you can set background colour for all of them.

            If that is your actual question: There is no Qt-mechanism I'm aware of that could do this. However you can implement such a mechanism pretty easily. For instance by adding a class-member QList<MyWidget*> and in the constructor of you class, add a pointer to the instance to that list.

            I didn't test s this code, but it would look similar to this:
            @
            class MyWidget : public QWidget{
            private:
            static QList<MyWidget*> instances;
            public:
            MyWidget(QWidget* parent=0);
            ~MyWidget();
            };
            @

            and

            @
            MyWidget::MyWidget(QWidget* parent) : QWidget(parent){
            instances.append(this);
            }

            MyWidget::~MyWidget(){
            instances.removeOne(this);
            }
            @

            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