小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

QT常用類

 niudp 2015-07-16
1. ListWidget類

listWidget = QListWidget() #實例化一個(itembase)的列表

listWidget.addItem('dd') #添加一個項

listWidget.addItems([]) # 從序列中添加子項

listWidget.setDragEnabled(True)#設(shè)置拖拉

listWidget.sortItems() #排序

listWidget.selectAll()全選

listWidget.setSortingEnabled(bool)#設(shè)置自動排序

listWidget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)#設(shè)置選擇模式

選擇模式有:ExtendedSelection 按住ctrl多選,SingleSelection 單選 MultiSelection 點擊多選 ContiguousSelection鼠標拖拉多選

listWidget.setCurrentRow(0) 設(shè)置當前選擇行默認為-1

listWidget.count() #得到子項總數(shù)

listWidget.item(row).text() #得到第 row行的內(nèi)容 listWidget.item(row) 返回一個item 對象

listWidget.takeItem(row) #返回row 行的所在的item 對象 可以用在 insertItem()中

listWidget.insertItem(2,item) #在第二行插入一項item 可謂為一個listviewitem對象 或者string

listWidget.setCurrentItem('dd')#設(shè)置'dd'為當前項

listWidget.selectedItems() 返回一個包含item對象 的list 對象

修改item 的內(nèi)容

item.setText('dsds') # 設(shè)置item的內(nèi)容為dsdsitem為對象 可從 listWidget.item(row) takeItem(row) 得到


QListWidget的用法

 

setSelectionMode()設(shè)置list一次最多可以選擇多少item

有兩種方法來listwidget中添加Item,一種是在item構(gòu)造時候,指定父widget,
如果item構(gòu)造時候QListWidget已經(jīng)存在,可以用下面的方法
new QListWidgetItem(tr("Oak"), listWidget);


第二種方法是構(gòu)造完item,在使用QListWidget::addItem()來添加item

 

向QListWidget中指定的位置插入item,使用QListWidget::insertItem(int , QListWidgetItem*)

 

使用QListWidget::count()來統(tǒng)計widget中總共的item數(shù)目
使用QListWidget::takeItem(int index)來刪除表中的某一項
打開和關(guān)閉item是否可以編輯使用QListWidget::openPersistentEditor(QListWidgetItem*)和

QListWidget::closePersistentEditor(QListWidgetItem*)
設(shè)置當前的item是第幾行,QListWidget::setCurrentRow ( int row )
設(shè)置list是否可以自動排序QListWidget::setSortingEnabled(bool),默認是FALSE

 

從list中查找是否含有某一項,
QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const


信號


void currentItemChanged ( QListWidgetItem * current, QListWidgetItem * previous )
void currentRowChanged ( int currentRow )
void currentTextChanged ( const QString & currentText )
void itemActivated ( QListWidgetItem * item )
void itemChanged ( QListWidgetItem * item )
void itemClicked ( QListWidgetItem * item )
void itemDoubleClicked ( QListWidgetItem * item )
void itemEntered ( QListWidgetItem * item )
void itemPressed ( QListWidgetItem * item )
void itemSelectionChanged ()

selectedItems() 方法,獲取被選中的項,可以是多項

當item改變時候,會發(fā)射信號currentItemChanged 、currentRowChanged、currentTextChanged 、itemSelectionChanged 、itemChanged ,感覺這些信號其實效果都是一樣的,只不過用在不同的時候


2. TextEdit 類

設(shè)置TextEdit的內(nèi)容為“”:text.setPlainText("")

獲取TextEdit的內(nèi)容:text.toPlainText()


3. ComboBox 類

ComboBox類詳細介紹: http://book.51cto.com/art/201203/323502.htm

fromComboBox = QComboBox() 添加一個 combobox

 fromComboBox.addItem(rates) 添加一個下拉選項

fromComboBox.addItems(["%d years" % x for x in range(2, 26)]) 從序列中添加

fromComboBox.setMaxVisibleItems(10) #設(shè)置最大顯示下列項 超過要使用滾動條拖拉

fromComboBox.setMaxCount(5) #設(shè)置最大下拉項 超過將不顯示

fromComboBox.setInsertPolicy(QComboBox.InsertAfterCurrent) #設(shè)置插入方式

插入方式有:NoInsert,InsertAtTop,InsertAtCurrent,InsertAtBottom,InsertAfterCurrent

InsertBeforeCurrent,InsertAlphabetically字面意思都好理解 最后一個是按字母表順序插入

QComboBox 發(fā)出一個currentIndexChanged(int) 的信號.

QComboBox 得到當前項 currentIndex() + 1 #QComboBox 默認的currentIndex為 -1

setCurrentIndex可以來設(shè)置當前的項

QVariant QComboBox::itemData ( int index, int role = Qt::UserRole ) const 返回給定index處的數(shù)據(jù)

QComboBox.findText('dsfds') #返回 內(nèi)容為dsfds的索引

QComboBox.setEditText()設(shè)置下拉列表要顯示的可編輯內(nèi)容

QComboBox 得到當前項文本內(nèi)容 currentText()

當QComboBox當前項發(fā)生變化時候,它會發(fā)出信號currentIndexChanged(int i),i是改變后當前項的下標,可以編寫SLOT來處理

設(shè)置ComboBox為可編輯下拉列表框:fromComboBox.editable = true

設(shè)置第一項為當前項目: fromComboBox.setCurrentIndex(0)


4. LineEdit 類

將LineEdit框設(shè)置成密碼輸入框:line.setEchoMode(QLineEdit::Password)

獲取linedit的值: line.text()

給lineedit 賦值為空: line.setText()


5. MessageBox 類

實例介紹:(實現(xiàn)提示框)

@kuang = Qt::MessageBox.new(Qt::MessageBox::NoIcon, "提示", "登錄成功!", 0, self)

@kuang.addButton("確定",Qt::MessageBox::AcceptRole)

@kuang.exec()

這樣就可以創(chuàng)建一個提示登錄成功的窗口。(注:這是在QtRuby 中的相關(guān)代碼。)


6. TabelWidget類

設(shè)置行表頭隱藏:

verticalHeader().setVisible(false);

設(shè)置列表頭隱藏:
horizontalHeader().setVisible(false);


    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多