本文整理汇总了C++中QToolBar::insertAction方法的典型用法代码示例。如果您正苦于以下问题:C++ QToolBar::insertAction方法的具体用法?C++ QToolBar::insertAction怎么用?C++ QToolBar::insertAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QToolBar
的用法示例。
在下文中一共展示了QToolBar::insertAction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertAction
void tst_QToolBar::insertAction()
{
QToolBar tb;
QAction action1(0);
QAction action2(0);
QAction action3(0);
QAction action4(0);
QCOMPARE(tb.actions().count(), 0);
tb.insertAction(0, &action1);
tb.insertAction(&action1, &action2);
tb.insertAction(&action2, &action3);
tb.insertAction(&action3, &action4);
QCOMPARE(tb.actions().count(), 4);
QCOMPARE(tb.actions()[0], &action4);
QCOMPARE(tb.actions()[1], &action3);
QCOMPARE(tb.actions()[2], &action2);
QCOMPARE(tb.actions()[3], &action1);
tb.clear();
QCOMPARE(tb.actions().count(), 0);
}
示例2: insertWidget
void tst_QToolBar::insertWidget()
{
QToolBar tb;
QWidget w(&tb);
QAction action1(0);
QAction action2(0);
tb.addAction(&action1);
tb.addAction(&action2);
QAction *widget = tb.insertWidget(&action2, &w);
QCOMPARE(tb.actions().count(), 3);
QCOMPARE(tb.actions()[0], &action1);
QCOMPARE(tb.actions()[1], widget);
QCOMPARE(tb.actions()[2], &action2);
// it should be possible to reuse the action returned by
// addWidget() to place the widget somewhere else in the toolbar
tb.removeAction(widget);
QCOMPARE(tb.actions().count(), 2);
QCOMPARE(tb.actions()[0], &action1);
QCOMPARE(tb.actions()[1], &action2);
tb.insertAction(&action1, widget);
QCOMPARE(tb.actions().count(), 3);
QCOMPARE(tb.actions()[0], widget);
QCOMPARE(tb.actions()[1], &action1);
QCOMPARE(tb.actions()[2], &action2);
tb.clear();
QCOMPARE(tb.actions().count(), 0);
{
QToolBar tb;
QPointer<QWidget> widget = new QWidget;
QAction *action = tb.addWidget(widget);
QVERIFY(action->parent() == &tb);
QToolBar tb2;
tb.removeAction(action);
tb2.addAction(action);
QVERIFY(widget && widget->parent() == &tb2);
QVERIFY(action->parent() == &tb2);
}
}
示例3: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->resize(800,680);
this->setWindowState(Qt::WindowMaximized);
ImageItem *image = new ImageItem();
//create ColorSelection
ColorSelection *CS1 = new ColorSelection(Qt::black);
ColorSelection *CS2 = new ColorSelection(Qt::white);
QObject::connect(CS1,SIGNAL(changeColor(QColor)),image,SLOT(setColor1(QColor)));
QObject::connect(image->getPipette(),SIGNAL(changeColor1(QColor)),CS1,SLOT(setColor(QColor)));
QObject::connect(CS2,SIGNAL(changeColor(QColor)),image,SLOT(setColor2(QColor)));
QObject::connect(image->getPipette(),SIGNAL(changeColor2(QColor)),CS2,SLOT(setColor(QColor)));
QHBoxLayout *Hlayout = new QHBoxLayout();
Hlayout->addStretch(5);
Hlayout->addWidget(CS1);
Hlayout->addWidget(CS2);
Hlayout->addStretch(5);
//Create slider
QSlider *slider = new QSlider(Qt::Horizontal);
slider->setMaximum(100);
slider->setMinimum(1);
slider->setValue(10);
QObject::connect(slider,SIGNAL(valueChanged(int)),image,SLOT(setSize(int)));
QVBoxLayout *Blayout = new QVBoxLayout();
Blayout->addWidget(slider);
Blayout->addLayout(Hlayout);
QWidget *wdg = new QWidget();
wdg->setLayout(Blayout);
// Create Dock
//
//
QDockWidget *dock = new QDockWidget(tr("Настройка"),this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
wdg->setFixedSize(200,100);
dock->setWidget(wdg);
dock->setMaximumHeight(300);
dock->setMaximumWidth(300);
addDockWidget(Qt::RightDockWidgetArea,dock);
QActionGroup *GP = new QActionGroup(this);
GP->addAction(ui->actionPencil);
GP->addAction(ui->actionEraser);
GP->addAction(ui->actionEllipse);
GP->addAction(ui->actionRectangle);
GP->addAction(ui->actionLine);
GP->addAction(ui->actionCurveLine);
GP->addAction(ui->actionFill);
GP->addAction(ui->actionPipette);
GP->addAction(ui->actionSelection);
GP->setExclusive(true);
//create tool bar
QToolBar *TB = new QToolBar();
TB->setAllowedAreas(Qt::TopToolBarArea | Qt::LeftToolBarArea);
TB->setFloatable(false);
TB->setMovable(true);
TB->insertAction(0,ui->actionSaveAs);
TB->insertAction(ui->actionSaveAs,ui->actionSave);
TB->insertAction(ui->actionSave,ui->actionOpen);
TB->insertAction(ui->actionOpen,ui->actionCreate);
TB->addSeparator();
TB->insertAction(0,ui->actionSelection);
TB->insertAction(ui->actionSelection,ui->actionPipette);
TB->insertAction(ui->actionPipette,ui->actionFill);
TB->insertAction(ui->actionFill,ui->actionCurveLine);
TB->insertAction(ui->actionCurveLine,ui->actionLine);
TB->insertAction(ui->actionLine,ui->actionRectangle);
TB->insertAction(ui->actionRectangle,ui->actionEllipse);
TB->insertAction(ui->actionEllipse,ui->actionEraser);
TB->insertAction(ui->actionEraser,ui->actionPencil);
addToolBar(Qt::TopToolBarArea, TB);
// create action connecting
QObject::connect(ui->actionOpen,SIGNAL(triggered(bool)),image,SLOT(open()));
QObject::connect(ui->actionSaveAs,SIGNAL(triggered(bool)),image,SLOT(saveAs()));
QObject::connect(ui->actionSave,SIGNAL(triggered(bool)),image,SLOT(save()));
QObject::connect(ui->actionPencil,SIGNAL(toggled(bool)),image,SLOT(setPencil(bool)));
QObject::connect(ui->actionEraser,SIGNAL(toggled(bool)),image,SLOT(setEraser(bool)));
QObject::connect(ui->actionEllipse,SIGNAL(toggled(bool)),image,SLOT(setEllipse(bool)));
QObject::connect(ui->actionRectangle,SIGNAL(toggled(bool)),image,SLOT(setRectangle(bool)));
QObject::connect(ui->actionLine,SIGNAL(toggled(bool)),image,SLOT(setLine(bool)));
QObject::connect(ui->actionCurveLine,SIGNAL(toggled(bool)),image,SLOT(setCurveLine(bool)));
QObject::connect(ui->actionFill,SIGNAL(toggled(bool)),image,SLOT(setFill(bool)));
QObject::connect(ui->actionPipette,SIGNAL(toggled(bool)),image,SLOT(setPipette(bool)));
QObject::connect(ui->actionSelection,SIGNAL(toggled(bool)),image,SLOT(setSelection(bool)));
//undo and redo
//.........这里部分代码省略.........