First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.

Slides:



Advertisements
Similar presentations
QT UI Widgets and Layout_1F
Advertisements

Confidential © 2008 Teleca AB QT coding conventions Author: Johnny Liu Date: July 14, 2010 Version: 1.0 Teleca Chengdu.
QT UI Widgets and Layout_2S
Timothy M. Shead Sandia National Laboratories
1 C++Tutorial Rob Jagnow This tutorial will be best for students who have at least had some exposure to Java or another comparable programming language.
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Rapid GUI Programming with Python and Qt
Sven Johannsen C++ User Group Aachen 01/08/15
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Lecture 4: Embedded Application Framework Qt Tutorial Cheng-Liang (Paul) Hsieh ECE 424 Embedded Systems Design.
QT GUI Programming CS340 – Software Design © 2009 – Jason Leigh University of Illinois at Chicago.
QT – Introduction C++ GUI Programming with Qt 4 Blanchette and Summerfield, Ch. 1 Miller, 2004.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Unix Process Environment. main Function A C program starts execution with a function called main. The prototype for the main function is: int main (int.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Advanced Programming in the UNIX Environment Hop Lee.
QT Intro. 김기형
L8: Qt4 Concept Qt Module QObject QObject Model Signal and Slot Qt Event Loop.
LAMAD Symbian Qt install and deploy Installing Qt SDK and deploying Qt applications.
Cross-platform approach to create the interactive application based on ROOT and Qt GUI libraries Rene Brun (CERN) Valeri Fine (BNL,
LAMAD Symbian Qt Symbian OS One of the first modern mobile operating systems Most popular smartphone OS until the end of 2010 Main Nokia OS.
Oct ROOT 2002, CERN, Geneva Qt-Based Implementation of Low Level ROOT Graphical Layer By V.Fine.
Qt Igor November 8, 2002 Friday’s HENP Group Meeting.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
CSCI 104 Qt Intro Mark Redekopp David Kempe. 2 © Copyright 2013 Brent Nash & Mark Redekopp, All Rights Reserved Qt  What is QT? –Pronounced “cute” –An.
Qt – Introduction C++ GUI Programming with Qt 3
Blanchette and Summerfield, Ch. 2
FLTK Tutorial.
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
Using Qt for GUI development Brad Whitlock March 2002.
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.
Created by Terri Street Copyright, 2000  1,000,0001,000,000  500,000500,000  250,000250,000  125,000125,000  64,00064,000  32,00032,000  16,00016,000.
Computer Science 112 Fundamentals of Programming II Command Buttons and Responding to Events.
1 Chapter 12 GUI C/C++ Language Programming Wanxiang Che.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed.
QT – Dialog C++ GUI Programming with Qt 4 Qt 4.5 Reference Documentation Blanchette and Summerfield, Ch. 3.
-1- National Alliance for Medical Image Computing First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
Programming Fundamentals1 Chapter 8 OBJECT MANIPULATION - INHERITANCE.
Confidential © 2008 Teleca AB Creating Custom Widgets Author: Patricia Jiang Date: July 29, 2010 Version: 1.0 Teleca Chengdu.
QT Programming QT Programming Ruku Roychowdhury. Background QT is a cross platform application framework. Widely used to develop GUI applications. Originally.
July Doxygen A Code Documentation System Doxygen generates documentation directly from the structure and comments in the code –Browsable HTML documentation.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
15-410, S’ The Process Jan. 21, 2004 Dave Eckhardt Bruce Maggs L05_Process “System call abuse for fun & profit”
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
QT – Introduction C++ GUI Programming with Qt 4
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
QT – Windows, menus, and such C++ GUI Programming with Qt 4 Qt 4.5 Reference Documentation Blanchette and Summerfield, Ch. 3.
CSIS 123A Lecture 7 Static variables, destructors, & namespaces.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
1. 2 Qt Toolkit ● C++ toolkit for cross-platform GUI application development – GUI functions (GUI = graphical user interface) – Data access components,
C# for C++ Programmers 1.
Mobile Application Development with MeeGo™ - Touch Apps & UI Design
Mark Redekopp David Kempe
Slide design: Dr. Mark L. Hornick
HCI/CHI: Computer-Human Interaction
QT graphical user interface framework
CS212: Object Oriented Analysis and Design
Mobile Application Development with MeeGo™ - Programming with SDK
Qt Programming.
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
The Designer.
Custom Widgets & Events
GTK + Programming.
A multi-platform GUI-building program
Go4 GUI and GSI's QtROOT interface
Go4 GUI and GSI's QtROOT interface
A multi-platform GUI-building program
Presentation transcript:

First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010

Hello World! #include int main(int argc, char * argv[]) { QApplication app(argc, argv); QPushButton button(Hello World); button.show(); return app.exec(); } The QApplication object must be created before any GUI-related features of Qt are used. Enter the loop of events. Qt receives and processes user and system events and passes these on to the appropriate widgets.

Qt classes QObject QWidget QLabelQAbstractButton QPushButtonQCheckBox QAction QPaintDevice … …

QObjects The QObject class is the base class of all Qt objects When deleted, the parent deletes its children. class QObject { public: QObject(QObject * parent = 0); virtual ~QObject(); const QObjectList & children () const; void setParent(QObject * parent); }; Add itself to the parents children list. qobject.h

QWidgets If a widgets parent is 0, the widget is a window. When shown/hidden, the parent shows/hides its children. When enabled/disabled, the parent enables/disables its children (except for children explicitly hidden).

QObjects QObjects can be safely created on the heap. Be careful when instantiating on the stack. … int main(int argc, char* argv[]) { … QWidget parentWidget; QPushButton* button = new QPushButton(Hello World, parentWidget); … } parentWidgets destructor deletes button int main(int argc, char* argv[]) { … QWidget parentWidget; QPushButton button(Hello World, & parentWidget); … } int main(int argc, char* argv[]) { … QPushButton button(Hello World); QWidget parentWidget; button.setParent(&parentWidget); … } Error: button is deleted twice The destructor of button is called first, and it removes itself from its parent.

Non QObject May be instantiated on the heap or stack. Its safer to create them on the stack. … QVector * ages; … ages = new QVector (10); … delete ages; … QString firstName(John); QString lastName(Doe); Qvector ages; … ages.resize(10); …

QLayout – Geometry Manager Instead of specifying widget coordinates for each QWidget, use QLayouts. … QGroupBox* parameters = new QGroupBox(Parameters, this); QLabel* label = new QLabel(Number of Iterations:, parameters); QSpinBox* spinBox = new QSpinBox(parameters); … label->setGeometry(0, 0, 50, 20); spinBox->setGeometry(56, 0, 30, 20); … QGroupBox* parameters = new QGroupBox(Parameters, this); QLabel* label = new QLabel(Number of Iterations:, parameters); QSpinBox* spinBox = new QSpinBox(parameters); … QHBoxLayout* layout = new QHBoxLayout; layout->addWidget(label); layout->addWidget(spinBox); parameters->setLayout(layout); … Without QLayoutWith QLayout

QLayout class diagram QObject QLayout QStackedLayoutQBoxLayout QVBoxLayoutQHBoxLayout QGridLayoutQFormLayout

QLayout Example 1/2 QHBoxLayout QVBoxLayout … QHBoxLayout* layout = new QHBoxLayout; layout>addWidget(iterationNumberLabel); layout->addWidget(iterationNumberSpinBox); layout->addWidget(thresholdLabel); layout->addWidget(thresholdDoubleSpinBox); parameters->setLayout(layout); … QVBoxLayout* layout = new QVBoxLayout; layout>addWidget(iterationNumberLabel); layout->addWidget(iterationNumberSpinBox); layout->addWidget(thresholdLabel); layout->addWidget(thresholdDoubleSpinBox); parameters->setLayout(layout); …

Qlayout Example 2/2 QGridLayout QFormLayout QGridLayout* layout = new QGridLayout; layout>addWidget(iterationNumberLabel, 0, 0, 1, 1); layout->addWidget(iterationNumberSpinBox, 0, 1, 1, 1); layout->addWidget(thresholdLabel, 1, 0, 1, 1); layout->addWidget(thresholdDoubleSpinBox, 1, 1, 1, 1); parameters->setLayout(layout); … QFormLayout* layout = new QFormLayout; layout>setWidget(0, QFormLayout::LabelRole, iterationNumberLabel); layout->setWidget(0, QFormLayout::FieldRole, iterationNumberSpinBox); layout->setWidget(1, QFormLayout::LabelRole, thresholdLabel); layout->addWidget(1, QFormLayout::FieldRole, thresholdDoubleSpinBox); parameters->setLayout(layout); …

Signals & Slots Qt uses signals and slots for high-level events (listerners) and virtual methods for low-level events Type-safe callbacks Precompiler (moc) A class which emits a signal neither knows nor cares which slots receive the signal

Signals & Slots

Signals & Slots - Example... class QSlider: public QWidget { Q_OBJECT public: … public slots: void setValue(int value); … signals: void valueChanged(int value); … }; … void QSlider::setValue(int value) { … if (value != old) { emit valueChanged(value); } } … valueChanged() is not defined … int main(…) { … QSpinBox* spinBox = new QSpinBox(panel); QSlider* slider = new QSlider(panel); … QObject::connect(slider, SIGNAL(valueChanged(int)), spinBox, SLOT(setValue (int))); QObject::connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue (int))); … }... class QSpinBox: public QWidget { Q_OBJECT public: … public slots: void setValue(int value); … signals: void valueChanged(int value); … }; … void QSlider::setValue(int value) { … if (value != old) { emit valueChanged(value); } } … QSpinBox.h QSpinBox.cpp

Signals & Slots - Example PROJECT(MyProject) FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) SET(MyProject_SRCS MyWidget.cxx main.cxx) SET(MyProject_MOC_SRCS MyWidget.h) QT4_WRAP_CPP(MyProject_SRCS ${MyProject_MOC_SRCS}) ADD_EXECUTABLE( MyProject ${MyProject_SRCS}) TARGET_LINK_LIBRARIES(MyProject ${QT_LIBRARIES}) #include class MyWidget: public QWidget { Q_OBJECT public: MyWidget(QWidget* parent = 0); public slots: void setValue(int value); signals: void valueChanged(int value); private: int Value; }; #include MyWidget.h void MyWidget::MyWidget(QWidget* parent) : QWidget(parent) { } void MyWidget::setValue(int value) { if (value != this->Value) { value = this->Value; emit this->valueChanged(this->Value); } } MyWidget.h MyWidget.cxx CMakeLists.cxx #include #include MyWidget.h int maint(int argc, char* argv[]) { QApplication app(argc, argv); QGroupBox container; MyWidget w1(&container); MyWidget w2(&container); QObject::connect(w1, SIGNAL(valueChanged(int)), w2, SLOT(setValue(int))); container.show(); return app.exec(); } main.cxx

Signals & Slots – Good to remember 1 Every connection you make emits a signal – duplicate connections emit two signals. –break a connection using disconnect() You can connect a signal to a signal Signals can have default values _ … QObject::connect(loginPushbutton, SIGNAL(clicked()), this, SIGNAL(loginRequested())); … class MyWidget: public QObject { … signals: void mySignal(int value = 5); … }; … emit mySignal(); … emit mySignal(10); … QObject::connect(button, SIGNAL(clicked()), widget2, SLOT(updateScreen())); … QObject::connect(button, SIGNAL(clicked()), widget2, SLOT(updateScreen())); … MyWidget.h MyWidget.cxx

Signals & Slots – Good to remember 2 Slots are implemented as normal methods –Slots can be virtual, public, protected, private. Slot may have a shorter signature than the signal it receives –slots can ignore extra arguments. class MyWidget: public QObject { … protected slots: virtual void myAbstractSlot() = 0; … }; … QObject::connect(pushButton, SIGNAL(clicked()), this, SLOT(myAbstractSlot())); … QObject::connect(slider, SIGNAL(valueChanged(int)), this, SLOT(update())); … MyWidget.h MyWidget.cxx

Qt Designer

QtDesigner- Example … SET(MyProject_UI_SRCS Resources/UI/MyProject.ui) … QT4_WRAP_UI(MyProject_UI_CXX ${MyProject_UI_SRCS}) … #include #include ui_MyWidget.h class MyWidget: public Qwidget, Ui_MyWidget { … }; #include MyWidget.h #include "ui_MyWidget.h void MyWidget::MyWidget(QWidget* parent) : QWidget(parent) { this->setupUi(this); } MyWidget.h MyWidget.cxx CMakeLists.cxx #include #include MyWidget.h int maint(int argc, char* argv[]) { QApplication app(argc, argv); MyWidget w(0); w.show(); return app.exec(); } main.cxx