日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

QComboBox用法小列

系統 2029 0

fromComboBox = QComboBox() 添加一個 combobox


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

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

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

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

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

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

InsertBeforeCurrent,InsertAlphabetically

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

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

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

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

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

fromSpinBox = QDoubleSpinBox()


fromSpinBox.setRange(0.01, 10000000.00)

fromSpinBox.setSuffix(" %d") #設置后綴 如顯示 10.0%d

fromSpinBox.setPrefix('#d') #設置前綴
fromSpinBox.setValue(1.00) 設置值

QDoubleSpinBox 發出 valueChanged(double) 信號 有setValue(double)插槽

QComboxBox可以建立下拉選單,以供使用者選取項目,以下直接看個簡單的示範,程式中包括下拉選單,選擇選項之後會改變QLabel的文字內容:

    #include <QApplication>
    
#include <QWidget>
#include <QLabel>
#include <QComboBox>
#include <QVBoxLayout>
#include <QIcon>

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

QWidget *window = new QWidget;
window->setWindowTitle("QComboBox");
window->resize(300, 200);

QComboBox *combo = new QComboBox;
combo->setEditable(true);
combo->insertItem(0, QIcon( "caterpillar_head.jpg" ), "caterpillar");
combo->insertItem(1, QIcon( "momor_head.jpg" ), "momor");
combo->insertItem(2, QIcon( "bush_head.jpg" ), "bush");
combo->insertItem(3, QIcon( "bee_head.jpg" ), "bee");

QLabel *label = new QLabel("QComboBox");

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(combo);
layout->addWidget(label);

QObject::connect(combo, SIGNAL(activated(const QString &)),
label, SLOT(setText(const QString &)));

window->setLayout(layout);
window->show();

return app.exec();
}

QComboBox的setEditable()方法可設定下拉選單的選項是否可編輯,使用insertItem()插入選項 時,可以使用QIcon設定圖示,當您選擇下拉選單的某個項目時,會發出activated()的Signal,QString的部份即為選項文字,這邊 將之連接至QLabel的setText(),以改變QLabel的文字,一個程式執行的畫面如下:

QComboBox用法小列


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 乐都县| 资中县| 五家渠市| 恭城| 高青县| 和平县| 陆河县| 台山市| 南充市| 青铜峡市| 西林县| 合肥市| 类乌齐县| 阳东县| 法库县| 宝鸡市| 岫岩| 广汉市| 庄河市| 信丰县| 刚察县| 台南县| 图木舒克市| 肃南| 迁西县| 托克托县| 邵东县| 郓城县| 凤冈县| 昭平县| 扬中市| 张北县| 油尖旺区| 略阳县| 广东省| 新沂市| 宜兰市| 襄城县| 岱山县| 青铜峡市| 汨罗市|