カスタム GraphicsItem のペイント関数が CPU を 100% 消費することを発見しました (最悪の場合)。
私はそれがこれであることがわかりました:setTransformOriginPoint
他のすべての関数 (drawRect、Hight Quality アンチエイリアスの設定など) に対して。
面白いことに、私はそれを削除しましたが、すべて正常に機能しました。移動後に配置したので、おそらくその新しい変換原点に関連して回転します。しかし、とにかくうまくいきました...なぜだろう...
しかし、主な問題は、なぜ 100% なのかということです。
CPU使用率が高いアイテムのペイントのコードを提供します。
// Translate all to the center of the ruler calculated in the itemChange method.
painter->translate(rulerCenter_);
// rotate with the center where the ruler center is
//setTransformOriginPoint(rulerCenter_); <-- BRINGS 100% USAGE, NO SENSE WHY IT WORKS WITHOUT THIS.
painter->rotate(rulerRotation_);
// Set the color for the lines and quality of the lines
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(linesColor_);
// Draw long line of the ruler next to the wall
painter->drawLine(-length_/2,0,length_/2,0);
// Lines in the sides
painter->drawLine(-length_/2, 0, -length_/2, -sideLinesSize_);
painter->drawLine(length_/2, 0, length_/2, -sideLinesSize_);
// if we should flip the text for the user to read it properly...
if (flippedText_)
painter->rotate(180);
// Prepare for the text box, moving it to be centered
painter->translate(-textBox_.width()/2,-textBox_.height()/2);
// draw a box under the text so it hides whatever is under it
painter->setBrush(textBackgroundColor_);
painter->setPen(Qt::NoPen);
painter->drawRect(textBox_);
// Draw the text
painter->setPen(pen_);
painter->setFont(font_);
painter->setRenderHint(QPainter::HighQualityAntialiasing, true);
painter->drawText(textBox_, Qt::AlignCenter, meassureString_ );