[C++ GUI Programming with Qt4] chap6

1,934 views

Published on

C++ GUI Programming with Qt4 - Chap6

  • Be the first to comment

[C++ GUI Programming with Qt4] chap6

  1. 1. Ch 6 Layout Management Author: Tony
  2. 2. Absolute Positioning <ul><li>The user cannot resize the window
  3. 3. Some text may be truncated </li><ul><li>Unusually large font
  4. 4. Translate into another language </li></ul><li>The widget might have inappropriate sizes
  5. 5. The positions and sizes must be calculated manually </li></ul>
  6. 6. resizeEvent <ul><li>Set the widgets' geometries </li><ul><li>reserve the extra space for ensuring the user resizes the widget smoothly </li></ul></ul>
  7. 7. Layout Manager <ul><li>QLayout </li><ul><li>QHBoxLayout
  8. 8. QVBoxLayout
  9. 9. QGridLayout </li></ul></ul>
  10. 10. Margin & Spacing <ul><li>QLayout::setContentsMargins()
  11. 11. QLayout::setSpacing() </li></ul>
  12. 12. QGridLayout <ul><li>Add widget with matrix type </li><ul><li>layout->addWidget(widget, row, column, rowSpan, columnSpan); </li><ul><li>rowSpan = 1
  13. 13. columnSpan = 1 </li></ul></ul><li>addStretch() </li><ul><li>Excess space between close button and help button </li></ul></ul>
  14. 14. QSizePolicy
  15. 15. Preferred vs. Expanding <ul><li>The excess space will give to the Expanding widgets.
  16. 16. Preferred widgets stay at their size hint. </li></ul>
  17. 17. MinimumExpanding & Ignored <ul><li>They are used in older version of Qt
  18. 18. Replaced by </li><ul><li>Expanding
  19. 19. Reimplement minimumSizeHint() </li></ul></ul>
  20. 20. Stretch Factor <ul><li>Two factors to define the expanding rate </li><ul><li>QSizePolicy::setHorizontalStretch ( uchar stretchFactor )
  21. 21. QSizePolicy::setVerticalStretch ( uchar stretchFactor ) </li></ul></ul>
  22. 22. QStackedLayout <ul><li>Show the one of a set of </li><ul><li>Child widgets
  23. 23. Pages </li></ul><li>The pages are numbered from 0
  24. 24. Make a specific child widget visible </li><ul><li>setCurrentIndex() </li></ul></ul>
  25. 25. An Example of Preferences Dialog QListWidget QStackedLayout
  26. 26. Splitters <ul><li>Qsplitter class
  27. 27. Contain other widgets
  28. 28. Automatically placed side by side in the order in which they are created </li></ul>
  29. 29. An Example of Splitters
  30. 30. An Example of The Mail Client's Splitter Layout
  31. 31. An Example of The Mail Client's Splitter Layout (cont.) <ul><li>User resizes a window, Qsplitter normally distributes the space </li><ul><li>setStretchFactor() </li></ul></ul>
  32. 32. Scrolling Areas <ul><li>Simpler to use (comparison with QscrollBars)
  33. 33. Call setWidget() member function
  34. 34. setWidgetResizable()
  35. 35. ScrollBarPolicy </li><ul><li>setHorizontalScrollBarPolicy()
  36. 36. setVerticalScrollBarPolicy() </li></ul></ul>
  37. 38. Dock Windows
  38. 39. Dock Windows (cont.)
  39. 40. Dock Windows (cont.) <ul><li>QDockWidget class
  40. 41. SetFeatures() </li><ul><li>movable, closable, and floatable </li></ul><li>setAllowedAreas()
  41. 42. QMainWindow::setCorner()
  42. 43. Save the states </li><ul><li>QMainWindow::saveState()
  43. 44. QMainWindow::restoreState() </li></ul></ul>
  44. 45. Dock Windows (cont.)
  45. 46. Tool Bar
  46. 47. Tool Bar (cont.)
  47. 48. Tool Bar (cont.)
  48. 49. Multiple Documemt Interface (MDI)
  49. 50. MDI (cont.) <ul><li>QMidArea class </li><ul><li>Create it and make it central </li></ul></ul>
  50. 51. MDI (cont.)
  51. 52. Qt-specific Command-Line Options <ul><li>Options </li><ul><li>style </li><ul><li>motif, windows, and platinum </li></ul><li>font
  52. 53. graphicssystem </li><ul><li>raster, opengl </li></ul></ul><li>Arguments </li><ul><li>QApplication::arguments() </li></ul></ul>
  53. 54. Qt-specific Command-Line Options
  54. 55. Add a New Sub-window
  55. 56. Other Sub-window Operations <ul><li>closeActiveSubWindow()
  56. 57. closeAllSubWindow()
  57. 58. tileSubWindow()
  58. 59. cascadeSubWindow() </li></ul>

×