Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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")));
    mZoomInAction->setIconVisibleInMenu(true);
    connect(mZoomInAction, SIGNAL(triggered()), this, SLOT(zoomInAct()));
    zoomMenu->addAction(mZoomInAction);
    
    mZoomOutAction = new QAction(tr("Zoom Out"), this);
    mZoomOutAction->setIcon(QIcon::fromTheme("zoom-out", QIcon(":/media/actions-icons/zoom-out.png")));
    mZoomOutAction->setIconVisibleInMenu(true);
    connect(mZoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOutAct()));
    zoomMenu->addAction(mZoomOutAction);
    
    mZoomInAction = new QAction(tr("100%"), this);  //My code for 100% zoom. How to start ?
    
    QAction *advancedZoomAction = new QAction(tr("Advanced Zoom..."), this);
    advancedZoomAction->setIconVisibleInMenu(true);
    connect(advancedZoomAction, SIGNAL(triggered()), this, SLOT(advancedZoomAct()));
    zoomMenu->addAction(advancedZoomAction);
    
    
    mToolsMenu->addMenu(zoomMenu);
    

    @



  • 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