in Education by
I have a QGraphicsItem element (subclassesed from QGraphicsItem) that has as child a QGraphicsTextItem. The problem is that the paint(...) method of the QGraphicsItem is called infinitely. Here is the paint method from my QGraphicsItem element with the QGraphicsTextItem: void rectangle_element::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { painter->drawRoundedRect( -10, -10, 80, 40, 5, 5 ); painter->drawStaticText( -10, -10, QStaticText( "some text" ) ); text_item->setPlainText( "more text" ); } I cannot use setCacheMode with other flag than QGraphicsItem::CacheMode::NoCache. I'm using Qt 5.6. UPDATE: The text_item is a member of the class and it is initialized in the initialization list. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You set the text of text_item in the paint() method of the parent item, which seems to in turn trigger a repaint of the parent, thus creating an infinite loop. Generally, it's not a good idea to change items during paint operations. Keep in mind that the paint() method can be called with a high frequency. Probably there is some event triggering the need for a text change of text_item, like user interaction, which in turn calls a slot. This is the point where you should set the text. The drawing of the text itself is handled by the QGraphicsTextItem.

Related questions

0 votes
    I need to render a vector-only SVG without antialiasing in Qt; specifically, I don't want the resulting ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    A programmer builds a _________ to avoid repeating the same task or reduce complexity. (a) Function (b) Package ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which of the following code create n samples of size “size” with probability prob from the binomial? (a) z...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    I need to react in a main process to random events happening in a child process. I have implemented ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 27, 2022 in Education by JackTerrance
0 votes
    Ok. I'm working with the FW1FontWrapper code for use with DirectX : https://archive.codeplex.com/?p=fw1 This has removed ... hex back onto a UNIT32 UINT32 color = 0xFF + (ucolorb...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Ok. I'm working with the FW1FontWrapper code for use with DirectX : https://archive.codeplex.com/?p=fw1 This has removed ... hex back onto a UNIT32 UINT32 color = 0xFF + (ucolorb...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Ok. I'm working with the FW1FontWrapper code for use with DirectX : https://archive.codeplex.com/?p=fw1 This has removed ... hex back onto a UNIT32 UINT32 color = 0xFF + (ucolorb...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    The code below copies data from one vector into another. If the vectors are large then I guess this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    The code below copies data from one vector into another. If the vectors are large then I guess this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    A couple months ago I did a project in C++ with Visual Studio that I needed pthreads for, so I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Is there a way to utilise the GCC compiler whilst still being able to develop via the Visual Studio IDE ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 30, 2022 in Education by JackTerrance
0 votes
    Is there a way to utilise the GCC compiler whilst still being able to develop via the Visual Studio IDE ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    Is there a way to utilise the GCC compiler whilst still being able to develop via the Visual Studio IDE ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    I'd like to ensure my RAII class is always allocated on the stack. How do I prevent a class from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I'd like to ensure my RAII class is always allocated on the stack. How do I prevent a class from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
...