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. Insert QRectF into QGraphicsRectItem
Forum Update on Monday, May 27th 2025

Insert QRectF into QGraphicsRectItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
qrectfqgraphicsrecite
3 Posts 2 Posters 1.0k Views
  • 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.
  • mandruk1331M Offline
    mandruk1331M Offline
    mandruk1331
    wrote on last edited by mandruk1331
    #1

    I have created an instance of QRectF and I want it to a parameter of a QGraphicsRectItem but whe I try to pass it as a parameter the compiler says: Program finished unexpectedly. What am I doing wrong?
    QGraphicsRectItem *tempi;

    QList <QRectF> rectan;
    QList <QGraphicsRectItem*>draw_rectan;
    

    for(int i=0;i<random_numbers_.size();i++){
    QRectF temp;
    temp.setRect(i*25,0-random_numbers_[i],20,random_numbers_.at(i));
    rectan.append(temp);
    tempi->setRect(rectan.at(i));
    draw_rectan.append(tempi);

    }
    for(int i=0;i<random_numbers_.size();i++){
        scene->addRect(rectan.at(i),Pen,darkMagentaBrush);
    }
    

    Mandruk1331

    raven-worxR 1 Reply Last reply
    0
    • mandruk1331M mandruk1331

      I have created an instance of QRectF and I want it to a parameter of a QGraphicsRectItem but whe I try to pass it as a parameter the compiler says: Program finished unexpectedly. What am I doing wrong?
      QGraphicsRectItem *tempi;

      QList <QRectF> rectan;
      QList <QGraphicsRectItem*>draw_rectan;
      

      for(int i=0;i<random_numbers_.size();i++){
      QRectF temp;
      temp.setRect(i*25,0-random_numbers_[i],20,random_numbers_.at(i));
      rectan.append(temp);
      tempi->setRect(rectan.at(i));
      draw_rectan.append(tempi);

      }
      for(int i=0;i<random_numbers_.size();i++){
          scene->addRect(rectan.at(i),Pen,darkMagentaBrush);
      }
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @mandruk1331
      most probably because rectan.size() != random_numbers_.size() ?
      Since you are using rectan[i]/rectan.at(i) you need to make sure the index is within bounds.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      mandruk1331M 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @mandruk1331
        most probably because rectan.size() != random_numbers_.size() ?
        Since you are using rectan[i]/rectan.at(i) you need to make sure the index is within bounds.

        mandruk1331M Offline
        mandruk1331M Offline
        mandruk1331
        wrote on last edited by
        #3

        @raven-worx I think that it's the same rectan[i]/rectan.at(i) . I solved the problem,:
        QGraphicsRectItem *tempi = new QGraphicsRectItem;
        tempi->setRect(rectan.at(i));
        draw_rectan.append(tempi);
        I think it was overwriting data

        Mandruk1331

        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