QT – Introduction C++ GUI Programming with Qt 4 Blanchette and Summerfield, Ch. 1 Miller, 2004.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Prof. Muhammad Saeed. Procedure-Driven Programming Event-Driven Programming Events Messages Event Handlers GUI Windows and Multitasking Queues ( System.
First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
Lecture 4: Embedded Application Framework Qt Tutorial Cheng-Liang (Paul) Hsieh ECE 424 Embedded Systems Design.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Introduction to Windows Programming. First Windows Program This program simply displays a blank window. The following code is the minimum necessary to.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
IN-LAB # 1 - GETTING STARTED - BUT FIRST: 1.Project ideas - watch the scope!!! 2.Check accounts 3. Either myself or the TA need to check you off BEFORE.
First Windows Program Hello Windows. 2 HELLOWIN.C #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance,
Intro to Windows Programming Basic Ideas. Program Entry Point Int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
1 Standard Widget Toolkit. 2 SWT l a widget toolkit for Java developers l provides a portable API and tight integration with the underlying native OS.
GVE, Hallym University, Song, Chang Geun, Ph.D. 컴퓨터 그래픽스 응용 한림대학교 컴퓨터공학부 송 창근.
Qt – Introduction C++ GUI Programming with Qt 3
Blanchette and Summerfield, Ch. 2
Win32 API Programming Event-driven, graphics oriented Example: User clicks mouse over a program’s window area (an event) -- – Windows decodes HW signals.
Bertrand Bellenot ROOT Users Workshop Mar ROOT GUI Builder Status & Plans ROOT & External GUI World MFC, FOX, Qt, PVSS… Snapshot of the Future.
Software Construction Lecture 10 Frameworks
6. 마우스.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Designing Interface Components. Components Navigation components - the user uses these components to give instructions. Input – Components that are used.
GUI Widgets Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
QT – Introduction C++ GUI Programming with Qt 4
Using Qt for GUI development Brad Whitlock March 2002.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Presentation Outline Introduction Painting and Repainting GDI.
-1- National Alliance for Medical Image Computing First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
QT Programming QT Programming Ruku Roychowdhury. Background QT is a cross platform application framework. Widely used to develop GUI applications. Originally.
Dialog boxes Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance,
Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
QT – Introduction C++ GUI Programming with Qt 4
Fall UI Design and Implementation1 Lecture 17: Toolkits.
1 Programming and Software Engineering. 2 Software Development We can define two main classes of software: User-written software solve a particular problem,
The WM_NCHITTEST Message  This is an internal message used by Windows for generating all the other mouse messages.  Though it almost never needs to be.
Lecture # 6 Graphical User Interface(GUI). Introduction A graphical user interface (GUI) presents a user- friendly mechanism for interacting with an application.
Menus  Menus is a feature which is common to almost every windows applications. It is the one of the most common user interface elements around.  Windows.
9. 메뉴와 기타 자원. 1. 자원 – 아이콘, 커서, 메뉴, 대화상자는 모두 Windows 의 자원이다. – 자원은 데이터로 생각할 수 있으며, 프로그램의 EXE 파일에 저장된 다. – 실행 가능한 프로그램의 데이터 영역에는 존재하지 않는다. 자원은 프로그램 소스코드에.
Introduction to OpenGL
Learning Programming Windows API Morpheus Feb-28, 2008.
Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to.
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
1. 2 Qt Toolkit ● C++ toolkit for cross-platform GUI application development – GUI functions (GUI = graphical user interface) – Data access components,
Presentation Outline Introduction Painting and Repainting GDI.
HCI/CHI: Computer-Human Interaction
Windows Programming Lecture 09.
Window.
Windows Programming Model
QT graphical user interface framework
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Mobile Application Development with MeeGo™ - Programming with SDK
Queued and Nonqueued Messages
The program in traditional OS
Windows Programming Lecture 12
GTK + Programming.
Windows Programming Lecture 13
CS 1253 Visual Programming Unit I Windows Environment
Constructors, GUI’s(Using Swing) and ActionListner
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Graphics Laboratory Korea University
GUI Socket Application
Presentation transcript:

QT – Introduction C++ GUI Programming with Qt 4 Blanchette and Summerfield, Ch. 1 Miller, 2004

Overview About UI programming systems, or toolkits –View hierarchy, stroke drawing, pixel model, input handling, widgets –They are all alike and all different A software layer Qt, as software layer “above” Windows api, provides a different view –Makes most day to day things easier “Slots” and “signals” for event handling and inter-dialog communication Widget styles –Window system native, or common across platforms Qt ide and resources

About UI Programming Systems UI programming systems, or “toolkits”, consist of these elements –E.g., MS windows (below), Swing (AWT for Java), Motif (X-windows), Qt (cross- platform Components (view hierarchy) –Windows and child windows Stroke drawing package –GDI Pixel model –Bitmaps Input handling –Messages sent to a window procedure Widgets –Buttons, menus, text boxes

Examples MS WindowsSwingHTMLQt Components WindowsJComponentsElementsWindows Strokes GDIGraphics(none)Graphics Pixels BitmapsImageInline imagesImages Input Messages -> window proc ListenersJavascript event handlers Connections and slots Widgets Button, menu, textbox, … Jbutton, Jmenu, … Form controls, links Button, … All programming systems have these basic elements

Widgets Widget: again, “window gadget” (Qt), etc. –Controls, interactors, gizmos, gadgets At core of Qt programming paradigm Reusable user interface components Examples –Buttons, checkboxes, radio buttons –List boxes, combo boxes, drop-downs –Menus, toolbars –Scrollbars, splitters, zoomers –One-line text, multiline text, rich text –Trees, tables –Simple dialogs

Widgets Success (or unsuccess) story for user interface programming Advantages –Reuse of development effort Coding, testing, debugging, maintenance Design, iteration and evaluation –External consistency Disadvantages –Constrain designer’s thinking –Encourage menu & forms style, rather than richer direct manipulation style –May be used inappropriately E.g., instructions in title bar –Is WIMP all there is? –Long record of mediocre (but not really bad) interfaces

Widget Data Data used in widgets Embedded model –Application data must be copied into the widget –Changes must be copied out’ Linked model –Or, data binding –Application provides model satisfying an interface –Enables “data-bound” widgets, e.g. a table showing thousands of database rows, or a combo box with thousands of choices

UI Toolkits AthenaMotifGTK+Qt XLib Often built on top of other toolkits Can provide cross-platform portability May add more powerful features E.g., X Windows XLib provides view hierarchy, stroke drawing, input handling Xlib not provide widgets Toolkits do

UI Toolkits - Qt Qt MS WindowsXLibMac Cross-platform portability Re-implements native system look and feel Or, can have (program) internal consistency Extends widget set, e.g., spin boxes Qt provides C++, Java, and Python language bindings Also, allows direct access to other sw api’s/layers, e.g., OpenGL As well as, allows direct access to MS Windows API But, is much more efficient to program in

Remember this? Qt is easy … in many ways

Hello World 1: ~60 lines –WinMain HELLOWIN.C – Petzold --- (main just sets things up – quite a few things – very low level) #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("HelloWin") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } (cont’d)

Old Familiar WinMain (cont’d) hwnd = CreateWindow (szAppName, // window class name TEXT ("The Hello Program"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent win handle NULL, // window menu handle hInstance, // prog inst handle NULL) ; // creation parameters ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; }

Hello World: WinProc, the Message Handler Note similarity to paradigm message handler of any event driven architecture: LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, L … lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (message) { case WM_CREATE: PlaySound (TEXT("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ; return 0 ; case WM_PAINT: // “window redraws itself!” hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; // DefWindProc handles all message not handled in WndProc }

LOTS of “Windows functions” Calls Windows Function Calls HELLOWIN - 18 Windows functions: LoadIcon Loads an icon for use by a program. LoadCursor Loads a mouse cursor for use by a program. GetStockObject Obtains a graphic object, in this case a brush used for painting the window's background. RegisterClass Registers a window class for the program's window. MessageBox Displays a message box. CreateWindow Creates a window based on a window class. ShowWindow Shows the window on the screen. UpdateWindow Directs the window to paint itself. GetMessage Obtains a message from the message queue. TranslateMessage Translates some keyboard messages. DispatchMessage Sends a message to a window procedure. PlaySound Plays a sound file. BeginPaint Initiates the beginning of window painting. GetClientRect Obtains the dimensions of the window's client area. DrawText Displays a text string. EndPaint Ends window painting. PostQuitMessage Inserts a "quit" message into the message queue. DefWindowProc Performs default processing of messages.

Hello, Qt!

Hello, Qt! 9 lines! #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QLabel *label = new QLabel("Hello Qt!"); label->show(); return app.exec(); } A bit for dramatic effect, but there will be advantages Just a label in a field with no real “main window” Will look at some basics tonight Slots and signals (vs. event queues), and layouts (this is a GUI builder),

Hello, Qt! the details #include // Definitions of QApplication and #include // QLabel classes // Qt is truly object-oriented int main(int argc, char *argv[]) { QApplication app(argc, argv);// Creates a QApplication object to // manage app-wide resources QLabel *label = new QLabel("Hello Qt!");// Creates a QApplication widget (used as // a window) that displays string label->show();// Make label (window) visible return app.exec();// Passes control to Qt }// (would also delete QLabel)

Handling Events: Signals and Slots Qt not handle events (or event queue) directly Qt widgets emit signals when user action or change of state occurs Signal can be connected to a function, or slot –When signal emitted the slot, or function, is executed In example, will connect button’s clicked signal to slot, the function quit() –quit() is “built-in” QApplication function (object)

A Signal and A Slot #include // Include class definitions #include int main(int argc, char *argv[]) { QApplication app(argc, argv);// Create QApplication object QPushButton *button = new QPushButton("Quit");// Create labeled button // Associate (connect) a particular signal of this application with a slot QObject::connect ( button, SIGNAL(clicked()), &app, SLOT(quit()) ); button->show(); return app.exec();// Pass control to QT }

Synchronization & Layout of 2 Widgets Book example – can be complex Example code creates three widgets: –QSpinbox, QSlider, QWidget (application’s main window, will be parent of others) Using signals and slots of the QSpinbox and QSlider, set value of one depending on value set in the other –E.g., change spinbox value to 70, slider will move to appropriate position –Change slider to some position, spinbox value will be changed based on position “Layout manager” object will set size and position of widgets

“Setting up”, 1/3 #include // Include class definitions for #include // layout, #include // slider, #include // and spinbox int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *window = new QWidget;// Again, window will be widget window->setWindowTitle("Enter Your Age");// Not good interface design!

Create & Synchronize Widgets, 2/3 A little “tricky” … QSpinBox *spinBox = new QSpinBox;// Create spinbox and slider QSlider *slider = new QSlider(Qt::Horizontal); spinBox->setRange(0, 130);// Set/define range of each slider->setRange(0, 130); // As before, a particular widget signal causes a function (slot) to be called // here, when the value in the spinbox is changed, the function to set the value in the // slider is called, and passed the new value of the spinbox to be the new value of the slider QObject::connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int))); // … and vice versa QObject::connect(slider, SIGNAL(valueChanged(int)), spinBox, SLOT(setValue(int))); spinBox->setValue(35);// Set initial value for spinbox, slider will then get set

Layout of Widgets by Qt, 3/3 // Qt manages the relative positioning of the child windows, here, as BoxLayout QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(spinBox);// Place widgets in set to be layout->addWidget(slider);// poistioned window->setLayout(layout);// Installs layout manager on win window->show(); return app.exec(); }

Widget Styles Recall, Qt is cross-platform Can have Qt applications in windowing system style where executed (external consistency) or in same style across windowing systems (internal consistency)

Qt IDE Works fine

Qt IDE Open project Open file

Help Works fine

Help Works fine

End.