Qt 自定义QPrintPreviewDialog

Qt 自定义QPrintPreviewDialog,qt,printing,Qt,Printing,是否可以自定义QPrintPreviewDialog 我想定义放大和缩小功能 我知道这个问题已经问了几个月了,但我花了相当长的时间才弄明白,所以这里是: QPrintPreviewDialog preview(&printer, this); QList<QToolBar *> toolbarlist = preview.findChildren<QToolBar *>(); if(!toolbarlist.isEmpty()) { toolbarlist

是否可以自定义QPrintPreviewDialog


我想定义放大和缩小功能

我知道这个问题已经问了几个月了,但我花了相当长的时间才弄明白,所以这里是:

QPrintPreviewDialog preview(&printer, this);
QList<QToolBar *> toolbarlist = preview.findChildren<QToolBar *>();
if(!toolbarlist.isEmpty())
{
    toolbarlist.first()->actions().at(3)->setDisabled(true);
    toolbarlist.first()->actions().at(4)->setDisabled(true);
    toolbarlist.first()->actions().at(5)->setDisabled(true);
    //or to remove:
    //toolbarlist.first()->removeAction(toolbarlist.first()->actions().at(3));
    //toolbarlist.first()->removeAction(toolbarlist.first()->actions().at(3));
    //toolbarlist.first()->removeAction(toolbarlist.first()->actions().at(3));

    //alternatively you can add actions to the toolbar:
    //toolbarlist.first()->addAction(QIcon("icon.png"), tr("New Action"));
}

我知道这个问题已经问了几个月了,但我花了相当长的时间才弄明白,所以现在是:

QPrintPreviewDialog preview(&printer, this);
QList<QToolBar *> toolbarlist = preview.findChildren<QToolBar *>();
if(!toolbarlist.isEmpty())
{
    toolbarlist.first()->actions().at(3)->setDisabled(true);
    toolbarlist.first()->actions().at(4)->setDisabled(true);
    toolbarlist.first()->actions().at(5)->setDisabled(true);
    //or to remove:
    //toolbarlist.first()->removeAction(toolbarlist.first()->actions().at(3));
    //toolbarlist.first()->removeAction(toolbarlist.first()->actions().at(3));
    //toolbarlist.first()->removeAction(toolbarlist.first()->actions().at(3));

    //alternatively you can add actions to the toolbar:
    //toolbarlist.first()->addAction(QIcon("icon.png"), tr("New Action"));
}
谢谢,很好用

每个菜单项都可以访问

    QList<QToolBar *> toolbarlist = priview.findChildren<QToolBar *>();
    foreach(auto tool, toolbarlist )
    { 
        tool->setDisabled(true); 
   }
谢谢,很好用

每个菜单项都可以访问

    QList<QToolBar *> toolbarlist = priview.findChildren<QToolBar *>();
    foreach(auto tool, toolbarlist )
    { 
        tool->setDisabled(true); 
   }