How to add zoom options of 200%, 50% etc.

  • I need to Add some frequently used zooming setting under menu/Tools/Zoom, e.g. 200% 300% 50%.

    As you can see though there is already two options zoom In and zoom Out. and advanced zoom action. all these are in the menu tools tab. under zoom.

    Where can I read documentations about such code? Is there a quick trick to adding the zoom options I need ?

    @ QMenu *zoomMenu = new QMenu(tr("Zoom"));

    mZoomInAction = new QAction(tr("Zoom In"), this);
    mZoomInAction->setIcon(QIcon::fromTheme("zoom-in", QIcon(":/media/actions-icons/zoom-in.png")));
    connect(mZoomInAction, SIGNAL(triggered()), this, SLOT(zoomInAct()));
    mZoomOutAction = new QAction(tr("Zoom Out"), this);
    mZoomOutAction->setIcon(QIcon::fromTheme("zoom-out", QIcon(":/media/actions-icons/zoom-out.png")));
    connect(mZoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOutAct()));
    mZoomInAction = new QAction(tr("100%"), this);  //My code for 100% zoom. How to start ?
    QAction *advancedZoomAction = new QAction(tr("Advanced Zoom..."), this);
    connect(advancedZoomAction, SIGNAL(triggered()), this, SLOT(advancedZoomAct()));


  • What do you need to zoom? In general you should multiply the height and width by a zoom factor: in your case, for 200 % you should multiply by 2 to get the "zoom"
    for example:
    void zoom2x()
    int factor = 2;
    widget()->resize(widget()->size() *factor);

    then you should add a QAction to context menu and connect it this slot..
    However there should be some example along with Qt, that use zoom with QGraphicsView...

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.