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.
  • M Offline
    M Offline
    mandruk1331
    wrote on 28 Jan 2016, 08:17 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

    R 1 Reply Last reply 28 Jan 2016, 08:27
    0
    • M mandruk1331
      28 Jan 2016, 08:17

      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);
      }
      
      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 28 Jan 2016, 08:27 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

      M 1 Reply Last reply 28 Jan 2016, 12:24
      0
      • R raven-worx
        28 Jan 2016, 08:27

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

        M Offline
        M Offline
        mandruk1331
        wrote on 28 Jan 2016, 12:24 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

        1/3

        28 Jan 2016, 08:17

        • Login

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