The central widget

As we have seen earlier, the central area of the QMainWindow can be occupied by any kind of widget. This widget can be any of the following:

  • A standard Qt widget such as QTextEdit or QGraphicsView
  • A custom widget created using primary widgets
  • Plain QWidget with a layout manager, which acts as a parent for many other widgets
  • Multiple widgets with a QSplitter which arranges the widgets horizontally or vertically
  • MDI area which acts as a parent for other MDI windows

In our example, we use QTextEdit as the central widget. The PySide.QtGui.QTextEdit class provides a widget that is used to edit and display both plain and rich text formats. QTextEdit is an advanced WYSIWYG viewer/editor supporting rich text formatting using HTML style tags. It can display text, images, lists, and tables as well. The rich text support in Qt is designed to provide a fast, portable, and efficient way to add reasonable online help facilities to applications, and to provide a basis for rich text editors. The QTextEdit can be both used as a display widget and an editor. For our purposes, we use it as an editor.

The following piece of code sets the QTextEdit as the central widget. On calling this function from main block by using the QApplication object, a text editor will be set at the central space of our application. The output is shown in the screenshot following the information box containing the code excerpt:

Note

  def SetupComponents(self):
    """ Setting the central widget
        """
        textEdit = QTextEdit()
		self.setCentralWidget(textEdit)
The central widget
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.4.191