2013-10-08 4 views
0

CPU 사용량을 제공합니다 (drawRect, Hight Quality 앤티 앨리어싱 설정 등).setTransformOriginPoint 내가 정의 GraphicsItem 내 페인트 기능은 내가이 있었다 발견</p> <p>(최악의 경우) CPU의 100 %를 소요 발견

재미있는 점은 내가 제거하고 모든 것이 잘 작동한다는 것입니다. 나는 번역 후에 그것을 넣었으므로 아마도 새로운 변환 원점과 관련하여 회전 할 것입니다. 하지만 어쨌든 작동 ... 왜 궁금해 ...

하지만 주요 질문은 : 왜 100 %? 당신은 다른 모든 처리 작업에서 렌더링 분리해야

// 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_); 
+0

왜 페인트 함수에서'setTransformOriginPoint()'를 호출하겠습니까? – thuga

답변

1

:

난 당신에게 그 CPU 사용량을주는 항목의 페인트에 대한 코드를 제공합니다.

페인트 기능은 움직이거나 회전하는 물체가 아니라 항목을 칠하기위한 것입니다. 페인트 기능에서 렌더링 이외의 작업을 시도하면 그래픽 파이프 라인이 지연되거나 정지됩니다. 이것은 setTransformOriginPoint를 호출 할 때 일어나는 일일 것입니다.

렌더링 전에 그래픽 파이프 라인을 설정하는 것은 상당한 처리량을 필요로합니다. 파이프 라인을 정지 시키면 다시 처리해야하는데 100 % 프로세서 시간을 고려해야합니다.

ARM 프로세서에서 어떤 일이 일어나는지 설명하지만 theory explained is the same here.

+0

고마워요! 하지만 이해가 안되는 것은 ... 항목을 배치 할 때마다 항목 또는 다른 항목으로 만든 복잡한 항목을 칠할 때마다 화가가 재설정되므로 항상 브러시를 이동시켜 선을 그려야하기 때문에, 회전, 다른 선 그리기, 등등 ... 나는 위치를 안다. 그러나 나는 페인트 할 때마다 그들을 다시로드해야한다! – darkgaze

+0

페인트 함수의 예제 코드를 질문에 추가하면 그 문제와 관련된 문제를 설명하겠습니다. – TheDarkKnight

+0

무슨 일이 벌어지는 지 알 수 있도록 코드를 추가했습니다. – darkgaze