Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add zoom options of 200%, 50% etc.
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mzein1292
    wrote on last edited by
    #1

    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);
    

    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ceora
      wrote on last edited by
      #2

      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...

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved