How to use QToolBar and QToolButton in Qt

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

Qttoolbar1.jpg

Making the toolbar movable

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

Note.png
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!

转载于:https://www.cnblogs.com/xj626852095/p/3648202.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值