Adding a New Option to the Framework. Introduction This is intended as a step by step guide to adding a new action to the menu or toolbar. The order of.

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Microsoft Word 2010 Lesson 1: Introduction to Word.
Page Features Footnotes and endnotes Headers and footers Page numbering Margins Columns.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
Programming Based on Events
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Cosc 4755 Phone programming: GUI Concepts & Threads.
1 Flash Programming Introduction Script Assist. 2 Course Description This course concentrates on the teaching of Actionscript, the programming language.
By: Jeremy Smith.  Introduction  Droid Draw  Add XML file  Layouts  LinearLayout  RelativeLayout  Objects  Notifications  Toast  Status Bar.
Outlook 2007 Tips, Tricks, and Tools. Overview Main Screen Navigation Pane View Pane Reading Pane To–Do Bar Create a New Message Contacts Create a Signature.
Programming Task: Task 1 Controlled Assessment Practice.
CHAPTER SIX Loop Structures.
CHAPTER 6 Loop Structures.
PROG Mobile Java Application Development PROG Mobile Java Application Development Event Handling Creating Menus.
CHAPTER SIX.
Visual Basic Chapter 1 Mr. Wangler.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
GLWidget Description Jason Goffeney 3/8/2006. GLWidget The GLWidget class extends the Qt QGLWidget. The QGLWidget is a Qt Widget that happens to have.
Introduction to Matlab & Data Analysis
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Getting Started The structure of a simple wxWidgets program, Look at where and how a wxWidgets application starts and ends, how to show the main window,
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
Classic Controls Trần Anh Tuấn A. Week 1 How to create a MFC project in VS 6.0 How to create a MFC project in VS 6.0 Introduction to Classic Controls.
Lab 6: event & input intro User Interface Lab: GUI Lab Oct. 2 nd, 2013.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
Concurrent Programming and Threads Threads Blocking a User Interface.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Topics Introduction Scene Graphs
CSC 157 (Blum)1 Hello World. CSC 157 (Blum)2 Start/Programs/Microsoft Visual Studio.NET 2003/Microsoft Visual Studio.NET 2003.
1 Command Processor II. 2 Command Processor Example Let's look at a simple example of a command processor using states and cities. Get initial information.
Object-Oriented Programming (Java), Unit 28 Kirk Scott 1.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Using Simulator With Undertow Suite. Source environment variables For example, envsource has all the environment variables set up. You can change the.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
QT Programming QT Programming Ruku Roychowdhury. Background QT is a cross platform application framework. Widely used to develop GUI applications. Originally.
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
QT – Windows, menus, and such C++ GUI Programming with Qt 4 Qt 4.5 Reference Documentation Blanchette and Summerfield, Ch. 3.
1NetBeans Tutorial Using the “Properties” menu, name the List “List1” and the button “Button1”. NetBeans Tutorial6.
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Visual C++ Programming: Concepts and Projects Chapter 10B: Recursion (Tutorial)
CIS 338: Events Dr. Ralph D. Westfall April, 2011.
Microsoft Expression Web 3 Chapter 6 Adding Interactivity.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
Creating Vector Graphics
Introduction to Events
Miscellaneous Topics #6: Polygons GUI Components and Event Handlers
Extend Text Editor to Draw shapes
Tonga Institute of Higher Education
Steps to Build Frame Window Recipe Application
Presentation transcript:

Adding a New Option to the Framework

Introduction This is intended as a step by step guide to adding a new action to the menu or toolbar. The order of steps is not necessary but useful from an instructional point of view. For this example I am going to have a button that draws a trapezoid when I press it.

Declare a New QAction QActions are generic items used by Qt to be added to toolbars and menus which provide a caption, a connection to the rest of the application and are triggerable. In MainWindow.h within the private section there is a set of QActions already declared so add it there. QAction *mousePolylineAct; QAction *mousePolygonAct; QAction *drawTrapezoidAct

Create QAction Within MainWindow.cpp is a method createActions() which creates all the actions used by the MainWindow widget. Instantiate the QAction with the caption Trapezoid drawTrapezoidAct = new QAction(tr(“Trapezoid"), this);

Create QAction Set the status tip which displays text in the status bar when the mouse cursor is over it. drawTrapezoidAct->setStatusTip(tr(“Draws a trapezoid")); Before we finish a brief discussion of Signals and Slots.

Signals and Slots Signals and Slots are the methods used by Qt to wire different widgets together Signals are messages transmitted when an event happens (a button is clicked, a slider is moved, etc.). Most Qt widgets have premade Signals like the QAction has triggered() which is fired when the mouse clicks it. You can also create your own but that is for another time.

Signals and Slots Slots are methods that are fired when it hears a signal is it listening for. Widgets often have slots already implemented but we will need to create our own for this example. Trapezoid QAction - drawTrapezoidAct GLWidget - glWindow Slot: setTrapezoidDrawing() Signal: triggered() connect

Signals and Slots Qt has a macro set up that provides the connection between a slot and a signal Usage: connect(object1, SIGNAL(object1Signal()), object2, SLOT(object2Slot())); The object that will fire an event The object that will handle the event The signal to be fired The method to handle the event

Create QAction Make the connection between the QAction’s trigger signal and the GLWidget’s slot (which will be created soon). connect(drawTrapezoidAct, SIGNAL(triggered()), glWindow, SLOT(drawTrapezoid()); To be declared and implemented in GLWidget class.

Add a New Toolbar Button Further down in MainWindow.cpp is the method createToolBar() which creates the toolbar and also adds the buttons to it. The toolbar’s addAction method adds a new item to the toolbar based on a created QAction. interactToolBar = addToolBar(tr("Interact")); interactToolBar->addAction(mouseLineAct); interactToolBar->addAction(mouseCircleAct); interactToolBar->addAction(mouseEllipseAct); interactToolBar->addAction(mousePolylineAct); interactToolBar->addAction(mousePolygonAct); interactToolBar->addAction(drawTrapezoidAct);

Add a Menu Item Alternately you can add a menu item within the method createMenus(). To add the QAction to the drawing menu you can use its addAction method. //The graphics menu graphicsMenu = menuBar()->addMenu(tr("&Graphics")); drawMenu = graphicsMenu->addMenu(tr("&Draw")); drawMenu->addAction(diagLineAct); drawMenu->addAction(diagCircleAct); drawMenu->addAction(diagEllipseAct); drawMenu->addAction(drawTrapezoidAct);

Add New Shape Option The job of the slot we are going to create is to set the shape we are going to be drawing. Inside GLWidget.h at the bottom of the public section is a set of variables which we will add a new constant class variable. static const int ELLIPSE; static const int POLYLINE; static const int POLYGON; static const int TRAPEZOID;

Add New Shape Option Now we need to initialize the class variable. At the top of GLWidget.cpp we will initialize the new constant class variable. const int GLWidget::ELLIPSE = 3; const int GLWidget::POLYGON = 4; const int GLWidget::POLYLINE = 5; const int GLWidget::TRAPEZOID = 6;

Creating a New Slot A slot is just like any other function / method but is declared as a slot. In GLWidget.h is a declaration section labeled public slots:. As would be expected these are slots with public scope.

Creating a New Slot Create the slot drawTrapezoid in GLWindow.h within the public slots section. /* >>>>>>>>>>>>>>>>>>>>>> Enables interactive polygon drawing */ void drawMousePolygon(); /* >>>>>>>>>>>>>>>>>>>>>> Enables the drawing of a trapezoid */ void drawTrapezoid();

Creating a New Slot Implement the slot drawTrapezoid in GLWindow.cpp. /* >>>>>>>>>>>>>>>>>>>>>>*/ void GLWidget::drawMouseLine() { drawMode = GLWidget::MOUSE; shapeMode = GLWidget::LINE; clearShapeVariables(); } /* >>>>>>>>>>>>>>>>>>>>>>*/ void GLWidget::drawTrapezoid() { shapeMode = GLWidget::TRAPEZOID; areShapesClear = false; }

Adding the Drawing Code All the drawing is called within the paintGL() method inside GLWidget.cpp. This method is called 50 times a second by a QTimer in the GLWidget constructor. The widget is cleared and then a shape to be drawn is selected in the switch statement.

Adding the Drawing Code Add a new case to the switch statement based on the variable we declared. case GLWidget::POLYGON: //stuff here break; case GLWidget::POLYLINE: //stuff here break; case GLWidget::TRAPEZOID: //stuff here break;

Adding the Drawing Code Here is some code that would draw a trapezoid based on the drawLine algorithm. case GLWidget::POLYLINE: //stuff here break; case GLWidget::TRAPEZOID: DrawingAlgorithms::drawLine(-10, 10, 10, 10); DrawingAlgorithms::drawLine(-20, -10, 20, -10); DrawingAlgorithms::drawLine(-10, 10, -20, -10); DrawingAlgorithms::drawLine(10, 10, 20, -10); break;

Compiling the Code Since we have done something with slots and signals we need to run qmake again to generate a new Makefile. QMake not only generates the Makefile but it also creates the support moc files which actually handle all this slots and signal stuff behind the scenes.

Finished This should allow you to add new toolbar or menus items to your applications. This does not cover everything you would ever need to know about Qt but should send you in the right direction.