Home > Articles > Programming > C/C++

C++ GUI Programming with Qt4: Implementing Application Functionality

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close Window

Jasmin BlanchetteMark Summerfield

Learn more…

Sorry, this author hasn't written any articles.

Sorry, this author doesn't have anything for sale.

Sorry, this author hasn't posted any blogs.

C++ GUI Programming with Qt4, 2nd Edition

This chapter is from the book
C++ GUI Programming with Qt4, 2nd Edition

This chapter completes the previous chapters' work on the Spreadsheet program by coding its underlying functionality.

4. Implementing Application Functionality

  • The Central Widget
  • Subclassing QTableWidget
  • Loading and Saving
  • Implementing the Edit Menu
  • Implementing the Other Menus
  • Subclassing QTableWidgetItem

In the previous two chapters, we explained how to create the Spreadsheet application's user interface. In this chapter, we will complete the program by coding its underlying functionality. Among other things, we will see how to load and save files, how to store data in memory, how to implement clipboard operations, and how to add support for spreadsheet formulas to QTableWidget.

The Central Widget

The central area of a QMainWindow can be occupied by any kind of widget. Here's an overview of the possibilities:

  1. Use a standard Qt widget.

    A standard widget such as QTableWidget or QTextEdit can be used as the central widget. In this case, the application's functionality, such as loading and saving files, must be implemented elsewhere (e.g., in a QMainWindow subclass).

  2. Use a custom widget.

    Specialized applications often need to show data in a custom widget. For example, an icon editor program would have an IconEditor widget as its central widget. Chapter 5 explains how to write custom widgets in Qt.

  3. Use a plain QWidget with a layout manager.

    Sometimes the application's central area is occupied by many widgets. This can be done by using a QWidget as the parent of all the other widgets, and using layout managers to size and position the child widgets.

  4. Use a splitter.

    Another way of using multiple widgets together is to use a QSplitter. The QSplitter arranges its child widgets horizontally or vertically, with splitter handles to give some sizing control to the user. Splitters can contain all kinds of widgets, including other splitters.

  5. Use an MDI area.

    If the application uses MDI, the central area is occupied by a QMdiArea widget, and each MDI window is a child of that widget.

Layouts, splitters, and MDI areas can be combined with standard Qt widgets or with custom widgets. Chapter 6 covers these classes in depth.

For the Spreadsheet application, a QTableWidget subclass is used as the central widget. The QTableWidget class already provides most of the spreadsheet capability we need, but it doesn't support clipboard operations and doesn't understand spreadsheet formulas such as "=A1+A2+A3". We will implement this missing functionality in the Spreadsheet class.

  • Share ThisShare This
  • Your Account

Discussions

Make a New Comment

You must log in in order to post a comment.

Related Resources

Danny KalevMinutes from the October 2009 Meeting
By Danny Kalev on November 19, 2009 No Comments

The minutes from the Santa Cruz (October 2009) meeting are available here. Even if you're not a language layer at heart, I encourage you to read them.

Danny KalevA Reader's Opinion on Attributes
By Danny Kalev on October 20, 2009 No Comments

In August I dedicated a series to the debate about C++0x attributes. I believe that it covered the subject in a balanced and detailed way, but I keep getting complaints from C++ users who don't like attributes for various reasons. Here's a recent email I received from a Polish C++ programmer. While it  doesn't represent my opinion about attributes -- I'm rather neutral about this feature and consider it a "solution waiting for a problem" -- but it suggests that attributes are still a highly controversial issue that will haunt C++ for a long time. The email is quoted here with minor edits that and as usual, with all private details removed.

Danny KalevFollowup: The Web 2.0 Guy I Ain't
By Danny Kalev on October 16, 2009 1 Comment

Almost a year ago, I posted here The Web 2.0 Guy I Ain't. People wonder whether I still resist all those Web 2.0 features and technologies at the end of 2009.

See All Related Blogs

Informit Network