漫谈.1
加速键和快捷键不一样
加速键:alt + ...
快捷键:ctrl + ...
加速键用来启用文件菜单,快捷键用来启用菜单里面的动作!
漫谈.2
toolButtonStyle | 设置图标和应用文本的显示及其相对位置 |
movabel | 设置状态栏是否可以移动 |
allowedArea | 设置允许停靠的位置 |
iconsize | 设置图标的大小 |
floatable | 设置是否可以悬浮 |
两点说明:
- 往工具栏添加部件可以使用addWidget()函数
- 其实往工具栏添加一个QAction类对象就会自动创建一个QToolButton,所以,工具栏上的动作就是一个QToolButton,这就解释了为什么属性栏有toolButtonStyle属性的原因。
演示 QToolButton和addWidget
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// create a tooButton
QToolButton *toolBtColor = new QToolButton(this);
toolBtColor->setText("color");
// crete a menu and add two action to menu
QMenu *menu = new QMenu(this);
menu->addAction("red");
menu->addAction("blue");
// add menu to tooButton
toolBtColor->setMenu(menu);
toolBtColor->setPopupMode(QToolButton::MenuButtonPopup);
ui->mainToolBar->addWidget(toolBtColor);
// add an widget to tooBar
QSpinBox *spinBox = new QSpinBox(this);
ui->mainToolBar->addWidget(spinBox);
}
参考: