2016-10-29 2 views
0

예를 들어 QGraphicsWidget입니다. 견인 단추, 확대/축소 단추 및 축소 단추를 추가하고 싶습니다. 코드 :버튼으로 QGraphicsWidget을 확대하고 축소하는 방법은 무엇입니까?

#include "myGraphicsWidget.h" 
int main(int argc,char* argv[]) 
{ 
    QApplication app(argc,argv); 
    QGraphicsScene scene; 

    myGraphicsWidget* graphicsWidget = new myGraphicsWidget("This is My Custom\n QGraphicsWidget!!"); 

    QGraphicsView view(&scene);   
    scene.addItem(graphicsWidget); 

    view.showFullScreen(); 

    return app.exec 

(); 

} 

줌 기능 (슬롯)을 쓰십시오.

답변

0

당신은 wheelEvent을 무시하거나를 QGraphicsView의 규모 처리 버튼을 만들어야합니다 슬롯에 대한

void myGraphicsWidget::wheelEvent(QWheelEvent *event) 
{ 
    qreal zoomFactor = 1.15; 
    if (event->delta() > 0 && zoomLevel < 20) { 
     // Zoom In 
     scale(zoomFactor, zoomFactor); 
    } else if (event->delta() < 0 && zoomLevel > 0) { 
     // Zooming out 
     scale(1.0/zoomFactor, 1.0/zoomFactor); 
    } 
    scrollViewTo(event->pos()); 
} 

을, 즉 같은 것 -하지만 당신은 zoomIn에 대한 코드를 분리해야하고 축소.