http://developer.nokia.com/Community/Wiki/How_to_use_QToolBar_and_QToolButton_in_Qt

How to use QToolBar and QToolButton in Qt

Introduction

This is a small code snippet which shows the use of the toolbar and tool button inQt.
With use of this code snippet one can easily create a small toolbar and adds buttons to it. Here all three buttons are set for same function that is to quit from application.

Code Snippet

#include <QApplication>
#include <QToolButton>
#include <QToolBar>
#include <QWidget>
#include <QVBoxLayout>
#include <QIcon>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *win = new QWidget;
QToolBar *tool = new QToolBar;
tool->setGeometry(0,0,200,20);
QVBoxLayout *layout = new QVBoxLayout;
QToolButton *button = new QToolButton;
button->setGeometry(0,0,10,20);
 
button->setIcon(QIcon("c://openbutton.png"));
QToolButton *button1 = new QToolButton;
button1->setIcon(QIcon("c://savebutton.png"));
QToolButton *button2 = new QToolButton;
button2->setIcon(QIcon("c://exitbutton.png"));
tool->addWidget(button);
tool->addSeparator();
tool->addWidget(button1);
tool->addSeparator();
tool->addWidget(button2);
layout->addWidget(tool);
win->setLayout(layout);
win->showMaximized();
return app.exec();
}

Screenshot

Making the toolbar movable

The toolbar can be made movable by using the following functions,

Note: This all function will work only when toolbar is placed in QMainWindow.
  • This function is used to move toolbar in QMainWindow.
toolbar->setMovable(1);
  • This is used to enable drag and drop toolbar.
toolbar->setFloatable(1);
  • This is used to know were toolbar is to be place in QMainWindow.
toolbar->setAllowedAreas(Qt::AllToolBarAreas);

More information

<?NOINDEX-START?>

Comments

This article shows the use of QtoolBar and QtoolButton.This article is one of the basic article of QT.

Tool button is a special button that provides quick-access to specific commands or options. As opposed to a normal command button, a tool button usually doesn't show a text label, but shows an icon instead.

The QToolBar class provides a movable panel that contains a set of controls.When a toolbar is resized in such a way that it is too small to show all the items it contains, an extension button will appear as the last item in the
toolbar. Pressing the extension button will pop up a menu containing the items that does not currently fit in the toolbar

--nayan_trivedi


Article shows the various functions of QtoolBar and QtoolButton. Introduction of the article explain every thing about the intact article. And in the end image partial with great hand.(things)

$ [--fasttrack 18:59, 12
September 2009 (UTC)]


QToolbar isn't supposed to be properly supported on Symbian. How does this look on a real device? Do you need to explicitly set geometry?

hamishwillee 22:14, 10 January 2011 (UTC)

NightOwl - Add QToolBar to "SoftKey Bar" / "Control Pane" / "Command Button Area"

Hello,

I have been searching everywhere on the web in hopes of finding a code example that shows how to add a QToolbar to the "SoftKey Bar" / "Control Pane" / "Command Button Area" (the default bar at the bottom of the screen). Would
someone please post an example of how to do this?

Thank you!

How to use QToolBar and QToolButton in Qt的更多相关文章

  1. qt 5.2.1类和模块的关系图

    QT│  ├─ActiveQt│  │  ActiveQt│  │  ActiveQtDepends│  │  ActiveQtVersion│  │  QAxAggregated│  │  QAxB ...

  2. QToolButton设置icon的大小

    项目中用到了QToolButton上使用图片. 如果在maindow中直接使用QToolButton,如: btnSimulate = new QToolButton; btnSimulate-> ...

  3. 用Qt写软件系列五:一个安全防护软件的制作(2)

    引言 在上一篇中讲述了主窗体的创建和设计.主窗体的无边框效果.阴影效果.拖动事件处理.窗体美化等工作在前面的博客中早就涉及,因此上篇博文中并未花费过多笔墨.这一篇继续讲述工具箱(Tool Button ...

  4. Qt Widgets——主窗口及其主要组成部分

    Main Window and Related Classes QAction 动作类,用于当做一个菜单项或工具项插入菜单或工具栏 QActionGroup 动作组,用于管理多个动作,设置它们之间的互 ...

  5. Qt与PyQT中设置ToolBar在AllowedArea的显示

    因为个人对传统的软件GUI界面不是太喜欢,最近又在学习Qt和PyQt5,所以就有了设置ToolBar在窗口的不同地方的想法,经过浪里淘沙,最终在Qt官网里找到了,原来再添加toolBar的时候是由设置 ...

  6. API Design Principles -- QT Project

    [the original link] One of Qt’s most reputed merits is its consistent, easy-to-learn, powerfulAPI. T ...

  7. qt_文本编辑器实现_附带详细注释和源码下载

    源码下载: 链接: http://pan.baidu.com/s/1c21EVRy 密码: qub8 实现主要的功能有:新建,打开,保存,另存为,查找(查找的时候需要先将光标放到最下面位置才能查全,不 ...

  8. QT_文本编辑器_源码下载

    源码下载: 链接: http://pan.baidu.com/s/1c21EVRy 密码: qub8 实现主要的功能有:新建,打开,保存,另存为,查找(查找的时候需要先将光标放到最下面位置才能查全,不 ...

  9. setStyleSheet 一些QSS设置的集合

    setStyleSheet 设置的一些集合,一部分源码和截图来自 http://blog.sina.com.cn/s/articlelist_2801495241_0_1.html 1. 设置QLab ...

随机推荐

  1. SteinerTree模板

    #define N 55//所有点的个数 #define K 10//SteinerTree 最大顶点数,必须精确 #define INF 10000000 //SteinerTree 邻接矩阵模板. ...

  2. 20160924-2——mysql常见问题集锦

    一.数据类型相关问题 1.varchar(N)占用多少空间 (1)varchar(N)里的N是字符数,而不是字节数: (2)字符类型(varchar text blob等)空间=字符实际长度+字段长度 ...

  3. MySQL事务隔离级别,锁(转)

    add by zhj: 本文针对的是MySQL的InnoDB存储引擎,不适用于MySQL的其它存储引擎和其它数据库 原文:MySQL数据库事务隔离级别(Transaction Isolation Le ...

  4. MySQL第二天

    回顾 数据库基础知识: 关系型数据库(磁盘)和非关系型数据库(内存)     关系型数据库: 建立在关系模型上的数据库 数据结构: 二维表(比较浪费空间) 操作数据的指令集合: SQL(DDL,DML ...

  5. 博客没内容可写了怎么办?找BD!

    博客写了一段时间可能会感觉没内容可以写了,或者说同一个领域的内容写多了感觉有点千篇一律,这时要考虑扩展自己的写作领域,怎么去扩展呢?利用关键词工具可以衍生很多长尾词,当然这个有点牵强,有点为优化而优化 ...

  6. 字符串之strstr

    功能:查找第二个字符串是否存在第一个字符串中. 输入:字符串1,字符串2 返回值:成功返回str1中的位置,失败返回NULL #include <iostream> using names ...

  7. ZFI_VENDOR_CREATE

    创建供应商函数, 需要考虑是 G_TASK = I /U /M FUNCTION zfyj_vendor_create. *"-------------------------------- ...

  8. Linux 使用pppd和ppp程序进行3G/4G拨号

    试验环境:Linux marsboard 3.4.90 #9 SMP PREEMPT Thu Mar 3 18:28:43 CST 2016 armv7l armv7l armv7l GNU/Linu ...

  9. EXCEL 从网页复制的内容 单/多选框 在EXCEL删不掉 及 2007添加开发工具选项卡

    从网页复制到Excel中的单选.多选框等,有时候删除时怎么都删不掉,很是恶心.这时候需要使用“开发工具”来删除.它是设计模式下的一种组件或者说控件. Excel 2007 的可以用下图方式按delet ...

  10. MySQL数据库(6)_用户操作与权限管理、视图、存储过程、触发器、基本函数

    用户操作与权限管理 MySQL用户操作 创建用户 方法一: CREATE USER语句创建 CREATE USER "用户名"@"IP地址" IDENTIFIE ...