-1- National Alliance for Medical Image Computing First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.

Slides:



Advertisements
Similar presentations
QT UI Widgets and Layout_2S
Advertisements

First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
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
Overloading Operators Overloading operators Unary operators Binary operators Member, non-member operators Friend functions and classes Function templates.
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 Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Operating Systems Course Hebrew University Spring 2007 Signals & User Thread.
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.
Advanced Programming in the UNIX Environment Hop Lee.
Linux Qt Graphical User Interface (GUI) Development In this session, we will cover Qt GUI development tools including: Qt Creator for remote debug and.
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,
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
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.
Qt Igor November 8, 2002 Friday’s HENP Group Meeting.
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
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
FLTK Tutorial.
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.
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.
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
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.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
CS415 C++ Programming Takamitsu Kawai x4212 G11 CERC building WV Virtual Environments Lab West Virginia University.
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.
Csi2172 class 5 Midterm: June 12. constructor Special method used to create objects of the class Never has a return type. Is called automatically upon.
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.
Dale Roberts Programming with Qt Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science,
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
Build Your Own Embedded System Qt User Interfaces for the Beagleboard Session 1 May 2010.
1. 2 Qt Toolkit ● C++ toolkit for cross-platform GUI application development – GUI functions (GUI = graphical user interface) – Data access components,
Introduction to Qt4 Diego Iastrubni - (only 71 slides!)
C# for C++ Programmers 1.
Mobile Application Development with MeeGo™ - Touch Apps & UI Design
Mark Redekopp David Kempe
Chapter 6 CS 3370 – C++ Functions.
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.
Conditional Statements
The Designer.
Custom Widgets & Events
GTK + Programming.
A multi-platform GUI-building program
Go4 GUI and GSI's QtROOT interface
Section 2 Processes January 27rd, 2017 Taught by Joshua Don.
Pointers and dynamic objects
Go4 GUI and GSI's QtROOT interface
A multi-platform GUI-building program
Presentation transcript:

-1- National Alliance for Medical Image Computing First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010

-2- National Alliance for Medical Image Computing 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.

-3- National Alliance for Medical Image Computing Qt classes QObject QWidget QLabelQAbstractButton QPushButtonQCheckBox QAction QPaintDevice … …

-4- National Alliance for Medical Image Computing 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 parent’s children list. qobject.h

-5- National Alliance for Medical Image Computing QWidgets If a widget’s 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).

-6- National Alliance for Medical Image Computing 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); … } parentWidget’s 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.

-7- National Alliance for Medical Image Computing Non QObject May be instantiated on the heap or stack. It’s 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); …

-8- National Alliance for Medical Image Computing 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

-9- National Alliance for Medical Image Computing QLayout class diagram QObject QLayout QStackedLayo ut QBoxLayout QVBoxLayoutQHBoxLayout QGridLayoutQFormLayout

-10- National Alliance for Medical Image Computing 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); …

-11- National Alliance for Medical Image Computing 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); …

-12- National Alliance for Medical Image Computing 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

-13- National Alliance for Medical Image Computing Signals & Slots

-14- National Alliance for Medical Image Computing 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

-15- National Alliance for Medical Image Computing 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

-16- National Alliance for Medical Image Computing 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

-17- National Alliance for Medical Image Computing 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

-18- National Alliance for Medical Image Computing Qt Designer

-19- National Alliance for Medical Image Computing 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