Title | Chapter 11 - Multiple documents and layouts |
---|---|
Author | Melinda Marais |
Course | Visual Programming II |
Institution | University of South Africa |
Pages | 4 |
File Size | 250.7 KB |
File Type | |
Total Downloads | 36 |
Total Views | 127 |
Download Chapter 11 - Multiple documents and layouts PDF
Chapter 11 – Multiple documents and layouts This chapter covers: A multiple document interface Layouts Displaying widgets collectively through Group Box
1. MULTIPLE-DOCUMENT INTERFACE SDI (Single-document interface) One document per main window MDI (Multiple-document interface) Consists of a main window containing Menu bar Toolbar and a central QWorkspace widget o Central workspace job – Display and manage several child windows MDI Enables you to Display multiple documents at the same time Each document displayed on its own window o One document acts as parent window o while other documents are its child windows To implement and MDI Use MdiArea widget instance of o QMdiArea class MdiArea widget Provides an area where child windows (subwindows) are displayed Arranges subwindows in o Cascade or o Tile pattern Documents in the mdi area can be viewed in two modes o Subwindow view o Tabbed view Subwindows are instances of o QMdiSubWindow class Methods provided by QMdiArea Method subWindowList() WindowOrder()
activateNextSubWindow() activatePreviousSubWindow() cascadeSubWindows() tileSubWindows() closeAllSubWindows() setViewMode()
Use Returns a list of all subwindows in the mdi area arranged in the order set through the WindowOrder() function Specify the criteria for ordering list of child windows returned by subWindowList() Available options: CreationOrder StackingOrder ActivationHistoryOrder Sets the focus to the next window in the list of child windows Sets the focus to the previous window in the list of child windows Arranges subwindows in cascade fashion Arranges subwindows in tile fashion Closes all subwindows Sets the view mode of the MDI area two modes: SubWindow view – Displays subwindows with window frames Tabbed view – Displays subwindows with tabs in a tab bar
Application Demo of the methods provided by QMdiArea import sys from mdidemo import * class MyForm(QtGui.QMainWindow): def __init__(self,parent=None): QtGui.QWidget.__init__(self,parent) self.ui=Ui_MainWindow() self.ui.setupUi(self) self.ui.mdiArea.addSubWindow(self.ui.subwindow) self.ui.mdiArea.addSubWindow(self.ui.subwindow_2) QtCore.QObject.connect(self.ui.showNextButton,QtCore.SIGNAL('clicked()'),self.shownext) QtCore.QObject.connect(self.ui.showPreviousButton,QtCore.SIGNAL('clicked()'),self.showprevious) QtCore.QObject.connect(self.ui.closeAllButton,QtCore.SIGNAL('clicked()'),self.closeall) QtCore.QObject.connect(self.ui.cascadeButton,QtCore.SIGNAL('clicked()'),self.cascade) QtCore.QObject.connect(self.ui.tileButton,QtCore.SIGNAL('clicked()'),self.tile) QtCore.QObject.connect(self.ui.subwindowButton,QtCore.SIGNAL('clicked()'),self.subwindowView) QtCore.QObject.connect(self.ui.tabbedButton,QtCore.SIGNAL('clicked()'),self.tabbedView) def shownext(self): self.ui.mdiArea.activateNextSubWindow() def showprevious(self): self.ui.mdiArea.activatePreviousSubWindow() def closeall(self): self.ui.mdiArea.closeAllSubWindows() #closes all the subwindows def cascade(self): self.ui.mdiArea.cascadeSubWindows()#arranges subwindows in cascade style def tile(self): self.ui.mdiArea.tileSubWindows()#arranges windows in tile style def subwindowView(self): self.ui.mdiArea.setViewMode(0) #sets view mode to subwindow view def tabbedView(self): self.ui.mdiArea.setViewMode(1) #sets view mode to tabbed view if __name__=="__main__": app=QtGui.QApplication(sys.argv) myapp=MyForm() myapp.show() sys.exit(app.exec_()) Cascade subwindows
Tile subwindows
setViewMode(0) – Subwindow view
setVewMode(1) – Tabbed view
2. LAYOUTS Layouts – Used to arrange and manage widgets Types of layouts Vertical layout Horizontal layout Grid layout Form layout sizeHint property Each widget has a recommended size and will adjust with the resizing of the window to meet their sizeHint minimumSize and maximumSize properties: Adjusting widget size constraints, overriding the default sizeHint property Spacers Expand to fill empty spaces HORIZONTAL LAYOUT Arranges widgets next to each other in a row VERTICAL LAYOUT Arranges widgets vertcally, in a column, below one another GRID LAYOUT Arranges widget in a stratchable grid
3. USING A GROUP BOX Groupbox – Used to represent information that is related in some way Instance of QGroupBox class Appears in a frame with a title
Properties of the group box Property checkable flat
Description Enable to display a checkbox in the Group Box’s title Space consumed by the Group Box is reduced
Methods supported by the QGroupBox class Method isCheckable() isChecked() setChecked()
Use Returns true if the Group Box has a checkbox in its title Returns true if the Group Box is checked Boolean value True makes the Group Box checkable
Signal
Generates a clicked() signal when the checkbox is selected...