0

My program produces runtime warnings when I type text into QGraphicsItems. The items are created like this:

QGraphicsTextItem* item = new QGraphicsTextItem(this)
item ->setTextInteractionFlags(Qt::TextEditorInteraction);
item ->setCacheMode(ItemCoordinateCache);

As soon as I start typing, the following warning is displayed:

QPainter::begin: Paint device returned engine 0, type: 2 

This also results in more warnings like the following, all stating that the painter is not active:

QPainter::translate: Painter not active 
QPainter::setClipRegion: Painter not active 
QPainter::setRenderHint: Painter must be active to set rendering hints 
QPainter::setWorldTransform: Painter not active 
QPainter::end: Painter not active, aborted

If I however set the cache mode to NoCache, everything is alright.

How do I fix this?

Tim Meyer
  • 12,210
  • 8
  • 64
  • 97
Lishen
  • 1
  • 1
  • 2
  • Can you provide the context in which your code lies? Is it the first thing in main, or have you setup a QGraphicsView and QGraphicsScene? – TheDarkKnight Mar 03 '14 at 08:37
  • i set up QGraphicsView and QGraphicsScene, and added into QGraphicsScene some custom graphic items Inherited from QGraphicsObject and all of this works fine with caching and without. – Lishen Mar 03 '14 at 12:03
  • item is child custom graphic object – Lishen Mar 03 '14 at 12:06
  • Please provide a smaller example that compiles. – Mitch Mar 03 '14 at 12:06
  • if add item into scene directly and type in text item single line all ok, if 2 and more lines then error – Lishen Mar 03 '14 at 12:16
  • auto item = new QGraphicsTextItem(); auto font = QFont(); font.setFamily("Arial"); font.setPointSize(17); font.setStyle(QFont::StyleNormal); item->setFont(font); item->setTextInteractionFlags(Qt::TextEditorInteraction); item->setPlainText("text"); item->setCacheMode(QGraphicsItem::ItemCoordinateCache); mScene->addItem(item); – Lishen Mar 03 '14 at 12:21
  • http://s020.radikal.ru/i716/1403/b8/608d5ee1bacb.png – Lishen Mar 03 '14 at 12:24
  • http://s020.radikal.ru/i723/1403/b2/b47c0f286f1d.png QPainter::begin: Paint device returned engine == 0, type: 2 – Lishen Mar 03 '14 at 12:28
  • if item lost focus all artefacts redrawn correctly – Lishen Mar 03 '14 at 12:33

0 Answers0