代码之家  ›  专栏  ›  技术社区  ›  Narek

在qt中缩放图形

  •  1
  • Narek  · 技术社区  · 15 年前

    我用 QGraphicsView QGraphicsScene 以便绘制图形。
    如何组织放大和缩小(放大时应出现滚动,缩小时应消失)?

    1 回复  |  直到 9 年前
        1
  •  5
  •   Community CDub    13 年前
    QGraphicsView::scale(qreal, qreal)
    
    e.g. 
    QGraphicsView * view = new QGraphicsView (parent);
    QGraphicsScene *scene = new QGraphicsScene();
    scene->addText("Hello World");
    view->setScene(scene);
    view->show();
    view->resize(100,100);
    
    // coll from some slot to see the effect
    view->scale(2,2);   //zoom in
    view->scale(.5,.5); //zoom out
    

    如果场景适合视图大小,滚动条将自动消失。

    当做, 瓦伦丁

    推荐文章