今天查了好多资料,发现做出来的都不理想。去查了下Qt源码。发现setView(QAbstractItemView *itemView)这个方法,官方的解释是这样的:
void QComboBox::setView(QAbstractItemView *itemView)
Sets the view to be used in the combobox popup to the given itemView. The combobox takes ownership of the view.
Note: If you want to use the convenience views (like QListWidget, QTableWidget or QTreeWidget), make sure to call setModel() on the combobox with the convenience widgets model before calling this function.
See also