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. Code for each object.
Forum Updated to NodeBB v4.3 + New Features

Code for each object.

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 188 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.
  • B Offline
    B Offline
    BottleOfYouLose
    wrote on last edited by
    #1

    Good day, I'm trying to apply code to each individual object that I create with an onclick listener. At the moment the logic applies to all objects at once regardless of the objects individually. Does anyone know how this can be done?

    This is the code I use to create the progressbar objects:

    void Bounce::mousePressEvent(QMouseEvent *event)
    {
        QProgressBar* stress = new QProgressBar(this);
        stress->move(LetItGo->x(), LetItGo->y()-stress->height());
        stress->show();
        stress->setValue(100);
        worry.push_back(stress);
    }
    

    This si the code I wanna apply to each individual object:

    for(auto stress : worry)
        {
    
                if((stress)->x() >= width())
                {
                    flag=1;
                    (stress)->setValue((stress)->value()-10);
                    NrOfBounces++;
                    if(NrOfBounces==10)
                    {
                        
    
                    }
                }
    
                if((stress)->x() <= 0)
                {
                    flag=0;
                    (stress)->setValue((stress)->value()-10);
                    NrOfBounces++;
                    if(NrOfBounces==10)
                    {
                       
                    }
                }
    
            if(flag==1)
            {
                horizontalspeed = -20;
    
            }
            else if(flag==0)
            {
                horizontalspeed = 20;
    
            }
            (stress)->move((stress)->x()+horizontalspeed, (stress)->y());
            /*if((stress)->x()+(stress)->height() > height())
            {
                verticalspeed = -3;
                (stress)->setValue((stress)->value()-10);
            }
            else if((stress)->x() < 0)
            {
                verticalspeed = 3;
                (stress)->setValue((stress)->value()-10);
            }*/
            count++;
         }
     }
    

    It's basically a function to bounce left when it hits the right edge of the form and bounce right when it hits the left. The problem is if one of the objects hit the left edge of the form, all the other existing objects bounce right along with the one that hit the wall. So I wanna apply this logic individually. Any help would be much appreciated!

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

      Hi and welcome to devnet,

      When is that code called ?

      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

      • Login

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