SlideShare une entreprise Scribd logo
1  sur  28
Qt chap4 2011/02/23 - Browny
Spreadsheet
Outline 4.1 The Central Widget 4.2 Subclassing QTableWidget 4.3 Loading and Saving 4.4 Implementing the Edit Menu 4.5 Implementing the Other Menu 4.6 Subclassing QTableWidgetItem
The central widget
The central widget 標準Qt窗口 widget QTableWidget, QTextEdit 功能如文件載入和儲存,必須在其他地方實現 (Qmain Window 的 subclass) 自定義窗口 widget 帶布局管理器的普通 widget 切分窗口 (Qsplitter) 多文檔介面
main.cpp
mainwindow.cpp
Outline 4.1 The Central Widget 4.2 Subclassing QTableWidget 4.3 Loading and Saving 4.4 Implementing the Edit Menu 4.5 Implementing the Other Menu 4.6 Subclassing QTableWidgetItem
QTableWidget, QTableWidgetItem Item class : 純數據類,並非繼承自 QObject,不能擁有signal, slot,也沒有使用 Q_OBJECT macro
const member variable(int) Spreadsheet.h
spreadsheet.cpp 允許矩行框選 QAbstractItemView QTableView setSelectionMode()
Spreadsheet::clear() QTableWidget 由多個子窗口 widget 所組成 QAbstractItemView QAbstractScrollArea
Outline 4.1 The Central Widget 4.2 Subclassing QTableWidget 4.3 Loading and Saving 4.4 Implementing the Edit Menu 4.5 Implementing the Other Menu 4.6 Subclassing QTableWidgetItem
QFile, QDataStream, (QTextStream) 各版本二進制表達方式不一定相同 檔頭 (識別檔案) 沙漏鼠標
Outline 4.1 The Central Widget 4.2 Subclassing QTableWidget 4.3 Loading and Saving 4.4 Implementing the Edit Menu 4.5 Implementing the Other Menu 4.6 Subclassing QTableWidgetItem
Edit Menu ::paste( ) ::copy( ) 把字串用 ‘’ 分行
Outline 4.1 The Central Widget 4.2 Subclassing QTableWidget 4.3 Loading and Saving 4.4 Implementing the Edit Menu 4.5 Implementing the Other Menu 4.6 Subclassing QTableWidgetItem
Other Menu 4.5 一開頭講 spreadsheet 變更後的自動刷新,關於 setDirty() 機制可以留待 4.6 釐清
Spreadsheet::sort() 仿函數 functor 把選取的資料存到Qlist<QStringList> 當中 根據  compare 決定如何排序
SpreadsheetCompare Override operator() 可擁有屬性
::operator() 參考 圖3.14 下方,keys 和 ascending 用來決定以哪一欄為主要/次要 排序依據。
Outline 4.1 The Central Widget 4.2 Subclassing QTableWidget 4.3 Loading and Saving 4.4 Implementing the Edit Menu 4.5 Implementing the Other Menu 4.6 Subclassing QTableWidgetItem
setDirty() ?
Spreadsheet::text()
Where is Cell::text() ? QTableWidgetItem provided convenient function text() = data.toSrting()
Cell::value() Got It ! 把表達式轉乘計算結果,與介面無關,跳過 XD
Conclusion 複雜的繼承體系,也許先了解基礎抽象類比較有個底 參考 Qt Class 大全 http://trinity.pearsoncomputing.net/docs/qt4/classes.html 善用 IDE 的 Type Hierarchy 功能
Thank You Q&A

Contenu connexe

Plus de Shih-Hsiang Lin

Plus de Shih-Hsiang Lin (11)

Ch6 file, saving states, and preferences
Ch6 file, saving states, and preferencesCh6 file, saving states, and preferences
Ch6 file, saving states, and preferences
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9
 
Ch5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internetCh5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internet
 
Ch4 creating user interfaces
Ch4 creating user interfacesCh4 creating user interfaces
Ch4 creating user interfaces
 
Ch3 creating application and activities
Ch3 creating application and activitiesCh3 creating application and activities
Ch3 creating application and activities
 
[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7
 
Function pointer
Function pointerFunction pointer
Function pointer
 
Introduction to homography
Introduction to homographyIntroduction to homography
Introduction to homography
 
Git basic
Git basicGit basic
Git basic
 
Project Hosting by Google
Project Hosting by GoogleProject Hosting by Google
Project Hosting by Google
 
An Introduction to Hidden Markov Model
An Introduction to Hidden Markov ModelAn Introduction to Hidden Markov Model
An Introduction to Hidden Markov Model
 

[C++ GUI Programming with Qt4] chap4