Chapter 14. Writing Your Own Widgets
In this chapter, you will learn how to write your own widgets. We first introduce you to the basics of widget writing and then present two widgets written for use with Qt: a coordinate selector and a browse box.
There are times when the widgets that Qt provides are not enough. You may have an application with special user-interaction needs or you may be required to support a fancy new interaction paradigm that Qt does not yet support. Qt makes it very easy to write your own widgets, especially if you compare its procedure to those of the MFC or Motif. Nevertheless, you should be reluctant to write widgets unless you absolutely need to do so. As explained in Chapter 7, nonstandard UIs are usually bad because users have to unlearn standard interaction procedures. Programmers tend to invent new ways of user interaction because it is more creative than simply exploiting available mechanisms. Marketing people also tend to demand new UI features to distinguish the application from its competitors. Remember, however, that usability and stability should always be the foremost criteria when writing an application.
A widget can be as little as a checkbox or as complex as a complete HTML widget in a web browser. Almost all of the “little” widgets that could be thought of when creating a GUI are present in Qt, but the appearance of a new UI paradigm could drive the need for smaller, more focused widgets. The two custom widgets presented in this chapter ...