10.7.  Exercises: MainWindows

[ fromfile: ex-mainwindows.xml id: ex-mainwindows ]

  1. Write a text editor application, with a QTextEdit as its central widget.

    • Show the filename and whether there are changes to be saved in the window title.

    • File Menu: Add actions for Open, Save as, and Quit.

    • Help Menu: Add actions for About and About Qt

    • If there are changes to be saved, ask the user to confirm the quit.

  2. Write an application that lets the user select and Open a text (or rich text) file from the disk and view the contents by scrolling through it. The scrolling view should expose several lines at a time (at least ten).

    It should also permit the user to search for a string in that file. If the string is found, the line that contains it should appear in the scrolling view so that the user can see its context within the file. If it is not found, an appropriate message should appear in the status bar.

    The user should click a button to search for the Next occurrence or the Previous occurrence of the search string.

    There should also be a Close button that removes the file from the display and invites the user to select another file or Quit.

    Figure 10.10 is a screenshot of one possible solution. The two menus contain actions that duplicate all of the pushbuttons except for Clear Search (which just clears the search text).

    Figure 10.10.  Text File Browser

    Text File Browser

  3. QTextEdit provides methods for undo and redo. Investigate these features and discuss the operations that can be undone or redone.