Programming with Qt - GBV

13 downloads 1983 Views 2MB Size Report
Why Qt? 3. Implementing Cross-Plattform GUI Libraries. 4. Acquiring Qt. 6. Compiling ... 2: First Steps in Qt Programming. 13 ... 21: Qt Network Programming . 271.
Programming with Qt Matthias Kalle

Dalheimer

O'REILLY8 Cambridge • Köln • Paris • Sebastopol • Taipei • Tokyo

Table of Contents Preface 1: Introduction Why GUI Toolkits? Why Portability? Why Qt? Implementing Cross-Plattform GUI Libraries Acquiring Qt Compiling and installing Qt C++ as used by Qt Getting Help

2: First Steps in Qt Programming Hello World! Using the Qt Reference Documentation Adding an Exit Button Introduction to Signals and Slots Event handling and simple drawings with QPainter

3: Learning More About Qt Adding Menus Adding a Scrolled View Adding a Context Menu File-I/O

xvii / 1 3 3 4 6 7 9 11

13 13 16 19 21 29

37 37 47 55 63

v

vi

Table of Contents

4: A Guided Tour Through the Simple Widgets General Widget Parameters Widget Styles Buttons Selection Widgets Widgets for Bounded Range Input Scroll bars Menu-related Widgets Arrangers Text Entry Fields Labels Widgets for the "Office Look" Progress bars Scrolled Views List Views Widgets for Tabular Material

5: A Guided Tour Through the Qt Dialogs Predefined Dialogs Building Blocks for Your Own Dialogs

6: Using Layout Managers Layout Manager Basics Laying Out Widgets in Rows and Columns Nested Layout Managers Grid Layout

75 77 77 79 81 85 87 89 91 94 95 98 104 105 106 Ill

113 113 118

125 125 127 130 132

7: Some Thoughts on GUI Design

137

8: Container Classes

143

Available Container Classes Choosing a Container Class Working with Container Classes Caching Data Iterators Stacks and Queues

143 145 145 147 148 149

Table of Contents

9: Graphics Animations Printing Managing Colors Basic QPainter: Drawing Figures Advanced QPainter: Two-dimensional Transformations and View Transformations Double Buffering and Other Nifty Techniques Loading and Saving Custom Image Formats Setting a Cursor

10: Text Processing Validating User Input Working with Regular Expressions

11: Working with Files and Directories Reading a Text File Traversing a directory File Information

12: Inter-Application Communication Using the clipboard Drag and Drop

Uli

151 151 153 157 l6l 163 168 173 177

179 179 184

189 189 191 193

197 197 202

13' Working with Date and Time Values

209

14: Writing Your Own Widgets

211

Implementing a Coordinate Selector Implementing a Browse Box

213 222

15: Focus Handling

237

16: Advanced Event Handling

241

Event Filters Sending Synthetic Events

241 243

viii

Table of Contents

17: Advanced Signals and Slots Signals and Slots Revisited Connecting Several Buttons to One Slot

245 245 248

18: Debugging

251

19: Portability

253

Why Portability Is Desirable How to Write Portable Programs Danger Ahead: When Even Qt Is Not Portable Building Projects Portably with tmake

20: Using GUI Builders QtArchitect QtEZ EBuilder

253 254 256 257

263 264 266 268

21: Qt Network Programming

271

22: Interfacing Qt with Other Languages and Libraries

279

OpenGL Programming with Qt Writing Netscape Plugins Integrating Xt Widgets Interfacing Qt with Perl

23: Using the Visual C++ IDEfor Qt Programs Importing an Existing Makefile Creating Your Own Project from Scratch Using tmake to Create a Project File

24: Sample Qt Projects The KDE Project OrthoVista

25: A First Look atQt2.0 Unicode Support and Improved QString Improved Layout Management

279 283 291 293

301 301 302 303

305 305 306

309 309 310

Table of Contents Internationalization Support Themability New or Improved Widgets Debugging Help Preventing Namespace Pollution Miscellaneous Changes The Future of Qt

ix 310 311 311 311 312 313 313

Appendix: Answers to Exercises

315

Bibliography

337

Index

339