1. QComboBox的底层实现
QComboBox底层是由QLineEdit和QComboBoxListView组成的。其中对QLineEdit和QComboBoxListView数据的管理则是通过QComboBoxPrivate类来处理。在QComboBoxPrivate中有个QComboBoxPrivateContainer* viewContainer();函数用于初始化QComboBox的view,其实现如下:
QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer()
{
if (container)
return container;
Q_Q(QComboBox);
container = new QComboBoxPrivateContainer(new QComboBoxListView(q), q);
container->itemView()->setModel(model);
container->itemView()->setTextElideMode(Qt::ElideMiddle);
updateDelegate(true);
updateLayoutDirection();
updateViewContainerPaletteAndOpacity();
QObject::connect(container, SIGNAL(itemSelected(QModelIndex)),
q, SLOT(_q_itemSelected(QModelIndex)));
QObject::connect(container->itemView()->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
q, S