QT缩放动作:200%,100%,50%

时间:2015-02-25 16:01:48

标签: c++ qt

问题是关于向工具缩放菜单添加:200%,100%和50%的缩放选项。

我在visual studio中运行了一个QT程序。我想在菜单中添加一个选项,可以选择100%,200%或50%的缩放选项。问题是我不知道在哪里阅读有关此类功能的文档,我很难理解下面的代码。

正如您所看到的,已经有两个选项放大和缩小。和高级缩放操作。所有这些都在菜单工具选项卡中。在缩放下。

我在哪里可以阅读有关此类代码的文档?是否有一个快速的技巧来添加我需要的缩放选项?

 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 个答案:

答案 0 :(得分:2)

mZoomIn50Action = new QAction(tr("50%"), this);
connect(mZoomIn50Action, &QAction::triggered, [this](){ zoom(50); });
zoomMenu->addAction(mZoomIn50Action );

mZoomIn100Action = new QAction(tr("100%"), this);
connect(mZoomIn100Action , &QAction::triggered, [this](){ zoom(100); });
zoomMenu->addAction(mZoomIn100Action);

mZoomIn200Action = new QAction(tr("200%"), this);
connect(mZoomIn200Action, &QAction::triggered, [this](){ zoom(200); });
zoomMenu->addAction(mZoomIn200Action);

zoom( uint percentage )课程中实施this