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. Java中,由this关键字引发的问题

    很久之前一直有一个疑问,最近重新翻了遍JVM的书,才算是终于有所顿悟.问题如下: 被自己遗忘的问题 package org.hanyan.test.testClass; public class T3 ...

  2. 使用 Docker 部署 MongoDB 复制集

    启用三个 mongod 建立复制集. MongoDB 版本选择目前最新的稳定版 3.6.2-jessie. docker run --name mongo0 -d mongo:3.6.2-jessie ...

  3. iOS CGAffineTransform你了解多少?

    CGAffineTransform介绍 概述 CGAffineTransform是一个用于处理形变的类,其可以改变控件的平移.缩放.旋转等,其坐标系统采用的是二维坐标系,即向右为x轴正方向,向下为y轴 ...

  4. sql的reader方法注意事项

    如果恢复注释. 在数据只有一条时,list将始终为空 原因很简单. 第一个红框已经跑完了.第二次调用的时候,就是第二条了,此时数据为空

  5. Webstorm如何设置背景色为护眼色(豆绿色)

    本文主要讲webstorm如何设置背景色. 1.打开idea Settings 选择 Editor——Color Scheme——General 注意:如果是Mac,在webstorm界面按键:“co ...

  6. Linux下Ngnix及PHP重启命令

    INT, TERM 立刻终止 QUIT 平滑终止 USR1 重新打开日志文件 USR2 平滑重载所有worker进程并重新载入配置和二进制模块 php-fpm 关闭: kill -INT `cat / ...

  7. python并发编程&协程

    0x01 前导 如何基于单线程来实现并发? 即只用一个主线程(可利用的cpu只有一个)情况下实现并发: 并发的本质:切换+保存状态 cpu正在运行一个任务,会在两种情况下切走去执行其他的任务(切换由操 ...

  8. pycharm中导入自写模块时,模块下出现红线

    问题描述: 在pycharm中导入自己写的模块时,得不到智能提示,并在模块名下出现下红线,但是代码可以执行,错误提示为下图所示: 原因:出现 以上情况,是因为文件目录设置的问题,pycharm中的最上 ...

  9. 前端基础-html(3)

    一.列表标签 1.ul(无序列表)标签 ul(unordered list)无序列表,ul下的子元素只能是li(list item),如下示例: <ul> <li>第一项< ...

  10. final 变量

    一.final对象 使用final关键字修饰一个变量时,是指引用不能变,引用的对象中的内容还是可以改变的.例如,对于如下语句: final StringBuffer a=new StringBuffe ...