久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 QComboBox 上設(shè)置不可選擇的默認(rèn)文本?

How to set non-selectable default text on QComboBox?(如何在 QComboBox 上設(shè)置不可選擇的默認(rèn)文本?)
本文介紹了如何在 QComboBox 上設(shè)置不可選擇的默認(rèn)文本?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

使用填充有項目的常規(guī) QComboBox,如果 currentIndex 設(shè)置為 -1,則小部件為空.在組合框中顯示初始描述性文本(例如--選擇國家/地區(qū)--"、--選擇主題--"等)會非常有用,該文本未顯示在下拉列表中.

Using a regular QComboBox populated with items, if currentIndex is set to -1, the widget is empty. It would be very useful to instead have an initial descriptive text visible in the combo box(e.g. "--Select Country--", "--Choose Topic--", etc.) which is not shown in the dropdown list.

我在文檔中找不到任何內(nèi)容,也沒有找到任何以前的問題的答案.

I couldn't find anything in the documentation, nor any previous questions with answers.

推薦答案

Combo Box API 中似乎沒有預(yù)料到這種情況.但是由于底層模型的靈活性,您似乎應(yīng)該能夠?qū)⒛?--Select Country-- 添加為第一個合法"項目,然后使其不被用戶選擇:

It doesn't appear that case was anticipated in the Combo Box API. But with the underlying model flexibility it seems you should be able to add your --Select Country-- as a first "legitimate" item, and then keep it from being user selectable:

QStandardItemModel* model =
        qobject_cast<QStandardItemModel*>(comboBox->model());
QModelIndex firstIndex = model->index(0, comboBox->modelColumn(),
        comboBox->rootModelIndex());
QStandardItem* firstItem = model->itemFromIndex(firstIndex);
firstItem->setSelectable(false);

根據(jù)您想要的精確行為,您可能希望改用 setEnabled.或者我個人更喜歡它,如果它只是我可以將其設(shè)置回的不同顏色的項目:

Depending on what precise behavior you want, you might want to use setEnabled instead. Or I'd personally prefer it if it was just a different color item that I could set it back to:

Qt,如何更改 QComboBox 的一項的文本顏色?(C++)

(我不喜歡當(dāng)我點擊某個東西然后被困在我無法回到原來的地方時,即使它是一個沒有選擇的狀態(tài)!)

這篇關(guān)于如何在 QComboBox 上設(shè)置不可選擇的默認(rèn)文本?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 国产精品国产精品国产专区不蜜 | 中文字幕日韩一区二区 | 日本午夜网站 | 国产精品中文字幕在线 | 精品国产一区二区三区av片 | 成人在线视| 国产韩国精品一区二区三区 | 狠狠躁躁夜夜躁波多野结依 | 国产一区二区在线免费播放 | 日韩精品1区2区 | 在线观看国产三级 | 麻豆av电影网 | 日韩午夜在线观看 | 一级黄色裸片 | 福利色导航 | 日韩在线91| 欧美日韩久 | 黄色一级免费观看 | 久久综合久久自在自线精品自 | 91干b| 在线免费亚洲视频 | 日韩亚洲视频 | 亚洲免费在线观看av | 欧美精品在线一区二区三区 | 97狠狠干 | 亚洲欧美成人影院 | 婷婷国产一区二区三区 | www.色综合| 国产91在线 | 亚洲 | 欧美一区二区三区 | 亚洲第一成年免费网站 | 你懂的国产 | 色片在线观看 | 国产精品区二区三区日本 | 国产精品久久在线观看 | 99精品欧美一区二区蜜桃免费 | 日本高清不卡视频 | 亚洲视频在线免费观看 | 日韩精品一区二区三区中文字幕 | 99在线国产| 日韩成人av在线 |