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

如何在 QComboBox 上設置不可選擇的默認文本?

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

問題描述

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

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.

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

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

推薦答案

Combo Box API 中似乎沒有預料到這種情況.但是由于底層模型的靈活性,您似乎應該能夠將您的 --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);

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

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++)

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

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

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

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 国产精品国产三级国产专区53 | 欧美国产视频 | 福利小视频在线观看 | 亚洲激情综合网 | 免费黄色小视频 | 国产天堂网 | 亚洲毛片在线 | 中文字幕一区二 | 亚洲欧美日韩国产精品 | 日本中文在线观看 | 日韩欧美亚洲 | 国产成人综合网 | 国产三级午夜理伦三级 | 综合激情网站 | 亚洲天堂一区二区三区 | 精品一区二区三区免费毛片 | 日本欧美久久久久免费播放网 | 国产精品一区在线播放 | 爱爱免费网站 | 在线观看视频一区二区 | 国语对白做受欧美 | 五月天一区二区 | 色婷婷av一区二区三区之e本道 | 黄色一级片视频 | 欧美日韩综合网 | 日本不卡视频 | 黄色小视频在线观看 | 欧美精品国产 | 国产成人福利 | 亚洲一区视频在线 | 日韩av免费在线观看 | 日韩不卡免费视频 | 成人在线免费视频 | 欧美日韩国产在线播放 | 91tv国产成人福利 | 国产精品偷乱一区二区三区 | 亚洲综人网| 国产激情久久久 | 日日干干 | 亚洲黄色三级 | 好吊视频一区二区三区四区 |