<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      pyqt model/view框架 1.第一個model

      >關(guān)于Qt的mvc模式就不多說了,網(wǎng)上很多很多,這里按著 Chen Chun-Chia的`《PyQt's Model/View Framework》`走一邊 我的第一個model --- class MyListModel(QAbstractListModel): """ 我的第一個模型 """ def __init__(self,parent=None): super(MyListModel,self).__init__(parent) #這是數(shù)據(jù) self._data=[70,90,20,50] pass def rowCount(self, parent=QModelIndex()): """ 這個方法返回了數(shù)據(jù)的行數(shù) 也就是有多少個條目得數(shù)據(jù) """ return len(self._data) def data(self,index,role=Qt.DisplayRole): """ 根據(jù)當(dāng)前index索引,返回當(dāng)前的數(shù)據(jù) 然后再由Qt進(jìn)行渲染顯示 """ #如果當(dāng)前得索引是不活動得 if not index.isValid() or not 0 <= index.row() < self.rowCount(): #亦或者當(dāng)前的索引值不在合理范圍,即小于等于0,超出總行數(shù) return QVariant() #返回一個QVariant,相當(dāng)與空條目 #從索引取得當(dāng)前的航號 row=index.row() #如果當(dāng)前角色是DisplayRole if role==Qt.DisplayRole: #返回當(dāng)前行的數(shù)據(jù) return self._data[row] #如果角色不滿足需求,則返回QVariant return QVariant() 代碼中,我們覆蓋了一個model中最基本得方法: `rowCount` 數(shù)據(jù)總行數(shù); `data` 獲取數(shù)據(jù); 并在__init__構(gòu)造方法中,設(shè)置好數(shù)據(jù)源`self._data` 運行下面的代碼試試看: # -*- coding: utf-8 -*- import sys from PyQt4.QtCore import * from PyQt4.QtGui import * #################################################################### def main(): app=QApplication(sys.argv) #新建一個ListView view=QListView() #新建一個自定義Model model=MyListModel() #設(shè)置view的model view.setModel(model) view.show() sys.exit(app.exec_()) #################################################################### class MyListModel(QAbstractListModel): """ 我的第一個模型 """ def __init__(self,parent=None): super(MyListModel,self).__init__(parent) #這是數(shù)據(jù) self._data=[70,90,20,50] pass def rowCount(self, parent=QModelIndex()): """ 這個方法返回了數(shù)據(jù)的行數(shù) 也就是有多少個條目得數(shù)據(jù) """ return len(self._data) def data(self,index,role=Qt.DisplayRole): """ 根據(jù)當(dāng)前index索引,返回當(dāng)前的數(shù)據(jù) 然后再由Qt進(jìn)行渲染顯示 """ #如果當(dāng)前得索引是不活動得 if not index.isValid() or not 0 <= index.row() < self.rowCount(): #亦或者當(dāng)前的索引值不在合理范圍,即小于等于0,超出總行數(shù) return QVariant() #返回一個QVariant,相當(dāng)與空條目 #從索引取得當(dāng)前的航號 row=index.row() #如果當(dāng)前角色是DisplayRole if role==Qt.DisplayRole: #返回當(dāng)前行的數(shù)據(jù) return self._data[row] #如果角色不滿足需求,則返回QVariant return QVariant() #################################################################### if __name__ == "__main__": main() 角色類型(Qt.ItemDataRole) --- The general purpose roles (and the associated types) are: Constant Value Description Qt.DisplayRole 0 The key data to be rendered in the form of text. (QString) Qt.DecorationRole 1 The data to be rendered as a decoration in the form of an icon. (QColor, QIcon or QPixmap) Qt.EditRole 2 The data in a form suitable for editing in an editor. (QString) Qt.ToolTipRole 3 The data displayed in the item's tooltip. (QString) Qt.StatusTipRole 4 The data displayed in the status bar. (QString) Qt.WhatsThisRole 5 The data displayed for the item in "What's This?" mode. (QString) Qt.SizeHintRole 13 The size hint for the item that will be supplied to views. (QSize) Roles describing appearance and meta data (with associated types): Constant Value Description Qt.FontRole 6 The font used for items rendered with the default delegate. (QFont) Qt.TextAlignmentRole 7 The alignment of the text for items rendered with the default delegate. (Qt.AlignmentFlag) Qt.BackgroundRole 8 The background brush used for items rendered with the default delegate. (QBrush) Qt.BackgroundColorRole 8 This role is obsolete. Use BackgroundRole instead. Qt.ForegroundRole 9 The foreground brush (text color, typically) used for items rendered with the default delegate. (QBrush) Qt.TextColorRole 9 This role is obsolete. Use ForegroundRole instead. Qt.CheckStateRole 10 This role is used to obtain the checked state of an item. (Qt.CheckState) Qt.InitialSortOrderRole 14 This role is used to obtain the initial sort order of a header view section. (Qt.SortOrder). This role was introduced in Qt 4.8. Accessibility roles (with associated types): Constant Value Description Qt.AccessibleTextRole 11 The text to be used by accessibility extensions and plugins, such as screen readers. (QString) Qt.AccessibleDescriptionRole 12 A description of the item for accessibility purposes. (QString) User roles: Constant Value Description Qt.UserRole 32 The first role that can be used for application-specific purposes. 最后的`Qt.UserRole`是用戶自定義Role,如果多個Role,可在他的基礎(chǔ)上加數(shù)字,比如`Qt.UserRole+1`,`Qt.UserRole+2` >目前為止,我們使用自定義Model完成了一個最基本的demo,并且知道了Qt.ItemDataRole的各種類型 > >[下一篇](http://www.rzrgm.cn/hangxin1940/archive/2012/12/07/2806449.html),將介紹Qt Model/View 中的委托 `Delegate`,通過它我們可以自由渲染view的顯示效果

      posted on 2012-04-23 01:12  黑暗伯爵  閱讀(5915)  評論(0)    收藏  舉報

      導(dǎo)航

      主站蜘蛛池模板: 亚洲欧美中文字幕日韩一区二区| 国内精品自线在拍| 国产成人精品亚洲精品日日| 九九热在线视频中文字幕| 国产360激情盗摄全集| 超碰人人超碰人人| 亚洲日本欧美日韩中文字幕| 美女内射毛片在线看免费人动物| 深夜免费av在线观看| 日本亚洲一区二区精品| 欧美综合自拍亚洲综合图| 国产精品69人妻我爱绿帽子| 国产精品美女久久久久久麻豆| 人人干人人噪人人摸| 亚洲无线码在线一区观看| 亚洲精品漫画一二三区| 精品国产av一区二区三区| 亚洲国产成人无码电影| 国产永久免费高清在线观看| 蜜臀久久精品亚洲一区| 国产亚洲精品在av| 亚洲一区中文字幕第十页| 国产在线自拍一区二区三区| 少妇性l交大片| 蜜桃av无码免费看永久| 日韩一区二区三区女优丝袜| 国产成人欧美一区二区三区在线| 日本一卡2卡3卡四卡精品网站| 亚洲中文字幕精品无人区| 亚洲熟女乱色一区二区三区| 日韩高清砖码一二区在线| 好男人官网资源在线观看| 福利一区二区不卡国产| 国产成人自拍小视频在线| 六十路老熟妇乱子伦视频| 乱码中文字幕| 蜜桃视频无码区在线观看| 国99久9在线 | 免费| 国产一区二区三区不卡视频| 国产一区二区a毛片色欲| 国产又色又爽又黄的|