QTableWidget 中的 QCombobox
我希望表格中的一个单元格成为 QComboBox。但是,我不希望它们始终显示为这样,仅当用户选择该单元格时才显示。有没有比检测单元格何时被单击、删除单元格中的项目并将其替换为小部件以及当用户从该单元格中单击时将其切换回项目更方便的方法来实现此目的?
I would like one of the cells in a table to be a QComboBox. However, I don't want them displayed as such all the time, only when a user selects that cells. Are there any more convenient ways of accomplishing this than detecting when a cell's been clicked, removing the item in the cell and replacing it with a widget, and switching it back to an item when the user's clicked away from that cell?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
方法是使用项目委托。您可以使用视图的 setItemDelegate 方法之一来安装委托/小部件。委托负责单元格的显示和编辑,您不必自己进行单击/按键处理。
有关此内容的文档位于模型/视图编程指南 委托类部分(带有示例)。
The way to do that is to use item delegates. You install your delegates using one of the setItemDelegate methods of the view/widget. The delegate is responsible for display and editing of the cell, and you don't have to do the click/key handling yourself.
The documentation for this is in the model/view programming guide delegate classes section (with examples).