Podstrony
- Strona startowa
- Linux. .Mandrake.10.Podręcznik.Użytkownika.[eBook.PL] (3)
- Sams' Teach Yourself Linux In 24 Hours
- Kirch O, Dawson T Linux. Podręcznik administratora sieci
- Teach Yourself Linux in 24 Hours (2)
- teach yourself linux in 24 hours
- Pierumow Nik Ostrze Elfow
- Dav
- Michael Grant Gone Zniknęli. Faza 5 CiemnoÂść
- balzac honoriusz komedia ludzka vi
- McCaffrey Anne Damia
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- fruttidimare.keep.pl
[ Pobierz całość w formacie PDF ]
.Additionally, you should learn how to use the available Qt C++ classesthat provide many ready-to-use user-interface components.You will see at the end of thischapter how easy it is to combine Qt widgets for application-specific purposes using newC++ classes.You saw in Chapter 30 how to use GTK to easily write X Windows applications in the Clanguage.You will see in this chapter that, for C++ programmers, it is probably evensimpler to write X Windows applications for Linux using Qt.If you prefer coding in Crather than C++, then you might want to skip this chapter and use either Athena widgets,Motif widgets, or GTK.Detailed documentation on Qt is available at www.troll.no/qt.In this short chapter, you will see how to use the following techniques:" Handle events by overriding event methods (for example, mousePressEvent)defined in the base Qt widget class QWidget." Handle events by using Qt signals and slots.A C++ pre-processor moc is provid-ed with the Qt distribution to automatically generate C++ code for using signalsand slots." Write new Qt widget classes by combining existing widget classes.The examples in this chapter are partially derived from the Troll Tech Qt example pro-grams and tutorial, so the following (representative) copyright applies to the exampleprograms for this chapter:/************************************************************************ $Id: connect.cpp,v 2.5 1998/06/16 11:39:32 warwick Exp $**** Copyright (C) 1992-1998 Troll Tech AS.All rights reserved.**** This file is part of an example program for Qt.This example** program may be used, distributed and modified without limitation.*************************************************************************/3672316072 CH31 7/26/99 2:08 PM Page 545GUI Programming Using Qt545CHAPTER 31This chapter uses two short examples.The first program shows how to draw graphics in31a window and how to handle events by overriding QWidget event methods.The QWidgetclass is a C++ base class for all other Qt widget classes.This example was derived fromthe connect Qt example program that can be found in the Qt distribution in the exam-ples directory.The second example uses the same Qt widget class (QLCDNumber) that isused in the Qt online tutorial example.For the second example in this chapter, we derivea new C++ widget class, StateLCDWidget, that adds two new slot methods for increas-ing and decreasing the value of the number shown in the widget.Other widgets can sendsignals to either of these slots to change the display value.We will see an example ofbinding signals (events) from two Push Button widgets to the two slots inStateLCDWidget class.Event-Handling By OverridingQWidget Class MethodsThe example program for this section is located in the src/Qt/events directory on theCD-ROM.This example program is very short only about 50 lines of code but showshow to create a simple main application window that uses Qt widgets (file main.cxx) andhow to derive a new widget class, DrawWidget, from the Qt QWidget class (filesdraw.hxx and draw.cxx).Before writing the example program for this section, we willlook at the most frequently used public interfaces for the C++ QWidget class.Later inthis chapter we will look at the alternative event-handling scheme in Qt that uses signalsand slots.Both event-handling schemes can be used together in the same program.Overview of the QWidget ClassThe QWidget class is the C++ base class for all other Qt widgets and provides the com-mon API for controlling widgets and setting widget parameters.The QWidget classdefines several event-handling methods that can be overridden in derived classes (fromthe qwidget.h file in the Qt distribution), as shown in the following:virtual void mousePressEvent(QMouseEvent *);virtual void mouseReleaseEvent(QMouseEvent *);virtual void mouseDoubleClickEvent(QMouseEvent *);virtual void mouseMoveEvent(QMouseEvent *);virtual void keyPressEvent(QKeyEvent *);virtual void keyReleaseEvent(QKeyEvent *);virtual void focusInEvent(QFocusEvent *);virtual void focusOutEvent(QFocusEvent *);virtual void enterEvent(QEvent *);virtual void leaveEvent(QEvent *);virtual void paintEvent(QPaintEvent *);PROGRAMMINGUSINGQTGUI3672316072 CH31 7/26/99 2:08 PM Page 546Programming the User Interface546PART IVvirtual void moveEvent(QMoveEvent *);virtual void resizeEvent(QResizeEvent *);virtual void closeEvent(QCloseEvent *);The purpose of these methods is obvious from the method names, but the event argumenttypes require a short explanation.The QMouseEvent class has the following (partial) pub-lic interface:class QMouseEvent : public QEvent { // mouse eventpublic:int x(); // x position in widgetint y(); // y position in widgetint globalX(); // x relative to X serverint globalY(); // y relative to X serverint button(); // button index (starts at zero)int state(); // state flags for mouse// constructors, and protected/private interface is not shown};The example in this section explicitly uses only mouse events.We will capture themouse s x-y position for mouse press and mouse movement events.We will not directlyuse the QKeyEvent, QEvent, QFocusEvent, QPaintEvent, QMoveEvent, QResizeEvent, orQCloseEvent classes in this chapter, but you can view their header files in the src/kernel subdirectory in the Qt distribution in the qevent.h file.It is beyond the scope ofthis short introductory chapter to cover all event types used by Qt, but you can quicklyfind the class headers in qevent.h for use as a reference
[ Pobierz całość w formacie PDF ]