一. QStatusBar 状态栏

它只有在QMainWindow才有,其它没有,但是可以手动添加,如下:

设置Label然后放到状态栏里:

  • .h:
  1. #include <QLabel>
  2. #include <QProgressBar>
  3. // 用于状态栏显示
  4. QLabel *statusLabel;
  5. QProgressBar *statusProgressBar;
  • .c:
  1. // create objects for the label and progress bar
  2. statusLabel = new QLabel(this);
  3. statusProgressBar = new QProgressBar(this);
  4. // set text for the label
  5. statusLabel->setText("Status Label");
  6. // make progress bar text invisible
  7. statusProgressBar->setTextVisible(false);
  8. ui->statusBar->addWidget(statusLabel);
  9. ui->statusBar->addWidget(statusProgressBar);

二. QToolBar

  • 里面加的是 QAction
  1. ui->toolBar->addAction(ui->actListAdd);

添加下拉按钮步骤:

  1. 先在 desiger 里新建一个 Action: actSelPopMen
  2. 再在代码中新建个菜单,把该菜单绑定到上面的 Action 中:
  1. QMenu *menu = new QMenu(this);
  2. menu->addAction(ui->actSelAll);
  3. menu->addAction(ui->actSelNone);
  4. menu->addAction(ui->actSelInvs);
  5. ui->actSelPopMenu->setMenu(menu);
  1. 最后把该 Action 添加到 ToolBar 上:
  1. ui->toolBar->addAction(ui->actSelPopMenu);