programming with qt - gbv

6
Programming with Qt Matthias Kalle Dalheimer O'REILLY 8 Cambridge Köln • Paris • Sebastopol • Taipei • Tokyo

Upload: others

Post on 21-Mar-2022

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Programming with Qt - GBV

Programming with Qt

Matthias Kalle Dalheimer

O'REILLY8

Cambridge • Köln • Paris • Sebastopol • Taipei • Tokyo

Page 2: Programming with Qt - GBV

Table of Contents

Preface xvii

1: Introduction / Why GUI Toolkits? 1 Why Portability? 3 Why Qt? 3 Implementing Cross-Plattform GUI Libraries 4 Acquiring Qt 6 Compiling and installing Qt 7 C++ as used by Qt 9 Getting Help 11

2: First Steps in Qt Programming 13

Hello World! 13 Using the Qt Reference Documentation 16 Adding an Exit Button 19 Introduction to Signals and Slots 21 Event handling and simple drawings with QPainter 29

3: Learning More About Qt 37 Adding Menus 37 Adding a Scrolled View 47

Adding a Context Menu 55 File-I/O 63

v

Page 3: Programming with Qt - GBV

vi Table of Contents

4: A Guided Tour Through the Simple Widgets 75 General Widget Parameters 77 Widget Styles 77 Buttons 79 Selection Widgets 81 Widgets for Bounded Range Input 85

Scroll bars 87 Menu-related Widgets 89 Arrangers 91 Text Entry Fields 94

Labels 95 Widgets for the "Office Look" 98 Progress bars 104 Scrolled Views 105 List Views 106 Widgets for Tabular Material I l l

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

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

7: Some Thoughts on GUI Design 137

8: Container Classes 143 Available Container Classes 143 Choosing a Container Class 145 Working with Container Classes 145 Caching Data 147 Iterators 148 Stacks and Queues 149

Page 4: Programming with Qt - GBV

Table of Contents Uli

9: Graphics 151 Animations 151 Printing 153 Managing Colors 157 Basic QPainter: Drawing Figures l6l Advanced QPainter: Two-dimensional Transformations and View Transformations 163 Double Buffering and Other Nifty Techniques 168 Loading and Saving Custom Image Formats 173 Setting a Cursor 177

10: Text Processing 179 Validating User Input 179 Working with Regular Expressions 184

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

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

13' Working with Date and Time Values 209

14: Writing Your Own Widgets 211 Implementing a Coordinate Selector 213 Implementing a Browse Box 222

15: Focus Handling 237

16: Advanced Event Handling 241 Event Filters 241 Sending Synthetic Events 243

Page 5: Programming with Qt - GBV

viii Table of Contents

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

18: Debugging 251

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

20: Using GUI Builders 263 QtArchitect 264

QtEZ 266 EBuilder 268

21: Qt Network Programming 271

22: Interfacing Qt with Other Languages and Libraries 279 OpenGL Programming with Qt 279 Writing Netscape Plugins 283 Integrating Xt Widgets 291 Interfacing Qt with Perl 293

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

24: Sample Qt Projects 305 The KDE Project 305 OrthoVista 306

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

Page 6: Programming with Qt - GBV

Table of Contents ix

Internationalization Support 310 Themability 311 New or Improved Widgets 311 Debugging Help 311 Preventing Namespace Pollution 312 Miscellaneous Changes 313 The Future of Qt 313

Appendix: Answers to Exercises 315

Bibliography 337

Index 339