QCombobox单元自定义的问题

坚持就会胜利来自未来 2018-08-28 11:28:09
我定义个qlistview,QCombobox设置view,使用函数setIndexWidget设置下拉框组合的Item,到后面完后,发现一个问题,就是QCombobox上有文本时,我点开下拉框(展开),我随便选中个单元(没按鼠标左键),没设置前不按住左键高光是不移动的,(设置)我在widget的mouseEnterEvent函数里设置了一旦鼠标进入就设置当前索引为这个widget的索引,(前面有点废话)我随便选中个单元后QCombobox的文本框就刷新原来的文本没了,我没按左键确定,debug发现我鼠标进入item的widget时,QCombobox也会触发事件,那些事件可能把原来的文字刷新走了。不像QQ,文本框只有点击下拉框的单元和打文本时匹配文本才会改变,我这个鼠标进入下拉框的单元就会把之前的清除,我看了别人类似的的自定义QCombobox也出现这样的情况,搞了半天都不行解决不了这个问题,如图所示,当我移动鼠标进入下拉框下拉视图的单元时,文本框自动清除了。
...全文
209 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
三岁、就很帅 2018-08-29
  • 打赏
  • 举报
回复
https://blog.csdn.net/ymc0329/article/details/7284498
你的描述能力不行啊 把没必要的删除了 然后在属性里面改
Assistant里面有解释

The QComboBox widget is a combined button and popup list.
A QComboBox provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space.
A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable, allowing the user to modify each item in the list.
Comboboxes can contain pixmaps as well as strings; the insertItem() and setItemText() functions are suitably overloaded. For editable comboboxes, the function clearEditText() is provided, to clear the displayed string without changing the combobox's contents.
There are two signals emitted if the current item of a combobox changes, currentIndexChanged() and activated(). currentIndexChanged() is always emitted regardless if the change was done programmatically or by user interaction, while activated() is only emitted when the change is caused by user interaction. The highlighted() signal is emitted when the user highlights an item in the combobox popup list. All three signals exist in two versions, one with a QString argument and one with an int argument. If the user selects or highlights a pixmap, only the int signals are emitted. Whenever the text of an editable combobox is changed the editTextChanged() signal is emitted.
When the user enters a new string in an editable combobox, the widget may or may not insert it, and it can insert it in several locations. The default policy is InsertAtBottom but you can change this using setInsertPolicy().
It is possible to constrain the input to an editable combobox using QValidator; see setValidator(). By default, any input is accepted.
A combobox can be populated using the insert functions, insertItem() and insertItems() for example. Items can be changed with setItemText(). An item can be removed with removeItem() and all items can be removed with clear(). The text of the current item is returned by currentText(), and the text of a numbered item is returned with text(). The current item can be set with setCurrentIndex(). The number of items in the combobox is returned by count(); the maximum number of items can be set with setMaxCount(). You can allow editing using setEditable(). For editable comboboxes you can set auto-completion using setCompleter() and whether or not the user can add duplicates is set with setDuplicatesEnabled().
QComboBox uses the model/view framework for its popup list and to store its items. By default a QStandardItemModel stores the items and a QListView subclass displays the popuplist. You can access the model and view directly (with model() and view()), but QComboBox also provides functions to set and get item data (e.g., setItemData() and itemText()). You can also set a new model and view (with setModel() and setView()). For the text and icon in the combobox label, the data in the model that has the Qt::DisplayRole and Qt::DecorationRole is used. Note that you cannot alter the SelectionMode of the view(), e.g., by using setSelectionMode().
  • 打赏
  • 举报
回复
引用 2 楼 swwllx 的回复:
https://blog.csdn.net/ymc0329/article/details/7284498
你的描述能力不行啊 把没必要的删除了 然后在属性里面改
Assistant里面有解释

The QComboBox widget is a combined button and popup list.
A QComboBox provides a means of presenting a list of options to the user in a way that takes up the minimum amount of screen space.
A combobox is a selection widget that displays the current item, and can pop up a list of selectable items. A combobox may be editable, allowing the user to modify each item in the list.
Comboboxes can contain pixmaps as well as strings; the insertItem() and setItemText() functions are suitably overloaded. For editable comboboxes, the function clearEditText() is provided, to clear the displayed string without changing the combobox's contents.
There are two signals emitted if the current item of a combobox changes, currentIndexChanged() and activated(). currentIndexChanged() is always emitted regardless if the change was done programmatically or by user interaction, while activated() is only emitted when the change is caused by user interaction. The highlighted() signal is emitted when the user highlights an item in the combobox popup list. All three signals exist in two versions, one with a QString argument and one with an int argument. If the user selects or highlights a pixmap, only the int signals are emitted. Whenever the text of an editable combobox is changed the editTextChanged() signal is emitted.
When the user enters a new string in an editable combobox, the widget may or may not insert it, and it can insert it in several locations. The default policy is InsertAtBottom but you can change this using setInsertPolicy().
It is possible to constrain the input to an editable combobox using QValidator; see setValidator(). By default, any input is accepted.
A combobox can be populated using the insert functions, insertItem() and insertItems() for example. Items can be changed with setItemText(). An item can be removed with removeItem() and all items can be removed with clear(). The text of the current item is returned by currentText(), and the text of a numbered item is returned with text(). The current item can be set with setCurrentIndex(). The number of items in the combobox is returned by count(); the maximum number of items can be set with setMaxCount(). You can allow editing using setEditable(). For editable comboboxes you can set auto-completion using setCompleter() and whether or not the user can add duplicates is set with setDuplicatesEnabled().
QComboBox uses the model/view framework for its popup list and to store its items. By default a QStandardItemModel stores the items and a QListView subclass displays the popuplist. You can access the model and view directly (with model() and view()), but QComboBox also provides functions to set and get item data (e.g., setItemData() and itemText()). You can also set a new model and view (with setModel() and setView()). For the text and icon in the combobox label, the data in the model that has the Qt::DisplayRole and Qt::DecorationRole is used. Note that you cannot alter the SelectionMode of the view(), e.g., by using setSelectionMode().
谢谢,因为看了这段话,说到setitemtext等函数,我找到了部分原因,原来要设置QStandardItem的text就不会出现combobox的编辑框会清除,但是会变为当前索引单元的文本(不管编辑框里是什么),我在看看是什么导致的。
  • 打赏
  • 举报
回复
果然发帖时间不对,都没人,我试试用禁止更新看看
课程亮点       本课程是PySide6零基础入门与项目实战视频教程,经过精心设计,分为十个章节,制作了141页ppt, 接近70个代码示例,主要讲解PySide6开发环境安装、基础控件与界面布局、项目实战,PySide6程序打包,安装包制作,安装卸载、更新,发布等知识。涵盖从基础概念到高级应用的全方位知识,旨在为你提供一条清晰、系统的学习之路。无论你是编程新手,还是希望深化对PySide6的了解,本课程都能满足你的需求。       教学环境:Win11 64bit、Python3.11、PyCharm、Anacoda。课程大纲第一章:基础篇 PySide6开发环境安装        从Anaconda环境配置开始,带你快速入门Win11/win10下PySide6、PyQt5开发环境的安装与配置,分别介绍PyCharm与VSCode如何配置PySide6,  以及Python AnaConda的基本用法,创建虚拟环境,安装python模块。第二章 控件与布局篇 PySide6常用控件与界面布局使用介绍        深入PySide6中的常用控件与界面布局技巧,通过丰富的实例,掌握PySide6的窗口、布局、控件等核心内容。主要介绍QLabel、QPushButton、QLineEdit、QCheckBox、QComboBox、QTextEdit、QTextBrowser、QListView与QListWidget、QStackedWidget、QTabWidget、QTableView等控件以及水平垂直布局,弹簧控件,栅格布局,表单布局。第三章 信号槽与事件机制       解锁PySide6的信号槽机制和事件处理技能,让你的应用更加灵活。详细介绍Qt自定义信号槽,跨窗口传递信号;Qt鼠标事件,键盘事件,组合事件,事件过滤。第四章 QMainWindow应用篇       详细介绍QMainWindow的使用,包括菜单栏、工具栏、状态栏和停靠窗口等。第五章 样式表qss与自定义控件        教你如何使用样式表美化应用界面,并创建独特的自定义控件。掌握这些技能后,学员将能够设计出既美观又功能丰富的用户界面。第六章 图表与曲线        引入pyqtgraph,展示如何在PySide6应用中绘制图表和动态曲线。第七章 数据库编程        带你进入数据库编程世界,使用sqlite3与PySide6结合,进行数据存储和管理。第八章 项目实战:高仿有道词典        通过一个高仿有道词典的项目,将所学知识融会贯通,实战演练。课程中将会接入翻译接口,开发一个属于自己的翻译软件。第九章 打包与部署       教你如何将PySide6项目打包成exe,并使用Inno Setup制作安装包,介绍软件更新、卸载策略,让你的应用轻松上线。第十章 课程总结        回顾整个课程的学习内容,巩固知识点,为进一步的学习和应用打下坚实的基础。教学特色       实战案例:每个章节都配备实战案例,让学习者在实践中深化理解。       代码资料全覆盖:提供全套课程代码资料下载,便于学习者随时查阅和复习。       高效学习路径:课程内容结构清晰,由浅入深,适合不同层次的学习者。       本课程提供全部代码与在线答疑。谁应该学习这个课程       对图形界面开发感兴趣的编程新手。       希望提升个人技能,进入或者深耕在GUI开发领域的开发者。       需要快速掌握PySide6进行项目开发的软件工程师。结语        通过本课程的学习,你不仅能掌握PySide6的核心技能,还能通过实战项目提升解决实际问题的能力,最终让你能独立完成专业的GUI应用开发。随着技术的深入,你将发现PySide6不仅仅是一个工具库,它开启的是一扇通往高效、美观应用开发的大门。        开始PySide6的学习之旅,让你的编程之路更加精彩!

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧