文章目录
1. 主窗口中的工具栏
-
工具栏的概念和意义
- 应用程序集成各种功能实现快捷键使用的一个区域
- 工具栏并不是应用程序中必须存在的组件
- 工具栏中的元素可以是各种窗口组件
- 工具栏中的元素通常以图标按钮的方式存在
-
在 QT 中提供与工具栏相关的组件
-
在 QT 主窗口中创建工具栏
// call member function QToolBar* tb = addToolBar("Tool Bar"); // create item for Tool Bar QAction* action = new QAction("",NULL); //set action property action->setToolTip("Open"); action->setIcon(QIcon(":/前缀/资源路径")); // add item to Tool Bar tb-addAction(action);
-
QToolBar 的关键成员函数
void setFloatable(bool floatable); void setMovable(bool movable); void setIconSize(const QSize& iconSize);
-
QToolBar 中可以加入任意的 QWidget 组件
QToolBar* tb = addToolBar("Tool Bar"); QPushButton* b = new QPushButton("Button"); QLabel* l = new QLabel("Label"); QLineEdit* e = new QLineEdit(); tb->addWidget(b); tb->addWidget(l); tb->addWidget(e);
2. 总结
- 工具栏是集成各种功能的一个快捷区域
- QT 中通过 QToolBar 进行工具栏的创建
- QToolBar 能够加入任意的 QWidget 组件
- QToolBar 中的元素通常以图标按钮的方式存在