📄 qcombobox.cpp
字号:
*/void QComboBox::focusOutEvent(QFocusEvent *e){ Q_D(QComboBox); update(); if (d->lineEdit) d->lineEdit->event(e);}/*! \reimp */void QComboBox::changeEvent(QEvent *e){ Q_D(QComboBox); switch (e->type()) { case QEvent::StyleChange: d->sizeHint = QSize(); // invalidate size hint if (d->lineEdit) d->updateLineEditGeometry(); //### need to update scrollers etc. as well here break; case QEvent::EnabledChange: if (!isEnabled()) hidePopup(); break; case QEvent::PaletteChange: d->viewContainer()->setPalette(palette()); break; case QEvent::FontChange: d->sizeHint = QSize(); // invalidate size hint d->viewContainer()->setFont(font()); if (d->lineEdit) d->updateLineEditGeometry(); break; default: break; } QWidget::changeEvent(e);}/*! \reimp*/void QComboBox::resizeEvent(QResizeEvent *){ Q_D(QComboBox); d->updateLineEditGeometry();}/*! \reimp*/void QComboBox::paintEvent(QPaintEvent *){ Q_D(QComboBox); QStylePainter painter(this); painter.setPen(palette().color(QPalette::Text)); // draw the combobox frame, focusrect and selected etc. QStyleOptionComboBox opt = d->getStyleOption(); painter.drawComplexControl(QStyle::CC_ComboBox, opt); // draw the icon and text painter.drawControl(QStyle::CE_ComboBoxLabel, opt);}/*! \reimp*/void QComboBox::showEvent(QShowEvent *e){ Q_D(QComboBox); if (!d->shownOnce && d->sizeAdjustPolicy == QComboBox::AdjustToContentsOnFirstShow) { d->sizeHint = QSize(); updateGeometry(); } d->shownOnce = true; QWidget::showEvent(e);}/*! \reimp*/void QComboBox::hideEvent(QHideEvent *){ hidePopup();}/*! \reimp*/bool QComboBox::event(QEvent *event){ Q_D(QComboBox); switch(event->type()) { case QEvent::HoverEnter: case QEvent::HoverLeave: case QEvent::HoverMove: if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event)) d->updateHoverControl(he->pos()); break; case QEvent::ShortcutOverride: if (d->lineEdit) return d->lineEdit->event(event); break;#ifdef QT_KEYPAD_NAVIGATION case QEvent::EnterEditFocus: if (!d->lineEdit) setEditFocus(false); // We never want edit focus if we are not editable break;#endif default: break; } return QWidget::event(event);}/*! \reimp*/void QComboBox::mousePressEvent(QMouseEvent *e){ Q_D(QComboBox); QStyleOptionComboBox opt = d->getStyleOption(); QStyle::SubControl sc = style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, e->pos(), this); if ((sc == QStyle::SC_ComboBoxArrow || !isEditable()) && !d->viewContainer()->isVisible()) { if (sc == QStyle::SC_ComboBoxArrow) d->updateArrow(QStyle::State_Sunken); d->viewContainer()->blockMouseReleaseTimer.start(QApplication::doubleClickInterval()); d->viewContainer()->initialClickPosition = e->pos(); showPopup(); }}/*! \reimp*/void QComboBox::mouseReleaseEvent(QMouseEvent *e){ Q_D(QComboBox); Q_UNUSED(e); d->updateArrow(QStyle::State_None);}/*! \reimp*/void QComboBox::keyPressEvent(QKeyEvent *e){ Q_D(QComboBox); int newIndex = currentIndex(); switch (e->key()) { case Qt::Key_Delete: case Qt::Key_Backspace: // skip autoCompletion if Delete or Backspace has been pressed d->skipCompletion = true; break; case Qt::Key_PageUp: case Qt::Key_Up:#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) e->ignore(); else#endif --newIndex; break; case Qt::Key_Down: if (e->modifiers() & Qt::AltModifier) { showPopup(); return; } // fall through case Qt::Key_PageDown:#ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) e->ignore(); else#endif ++newIndex; break; case Qt::Key_Home: if (!d->lineEdit) newIndex = 0; break; case Qt::Key_End: if (!d->lineEdit) newIndex = count() - 1; break; case Qt::Key_F4: if (!e->modifiers()) { showPopup(); return; } break; case Qt::Key_Space: if (!d->lineEdit) { showPopup(); return; } case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Escape: if (!d->lineEdit) e->ignore(); break;#ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Select: if (QApplication::keypadNavigationEnabled() && (!hasEditFocus() || !d->lineEdit)) { showPopup(); return; } break; case Qt::Key_Left: if (QApplication::keypadNavigationEnabled() && (!hasEditFocus() || !d->lineEdit)) --newIndex; break; case Qt::Key_Right: if (QApplication::keypadNavigationEnabled() && (!hasEditFocus() || !d->lineEdit)) ++newIndex; break; case Qt::Key_Back: if (QApplication::keypadNavigationEnabled()) { if (!hasEditFocus() || !d->lineEdit) e->ignore(); else if (d->lineEdit && hasEditFocus()) d->skipCompletion = true; } break;#endif default: if (!d->lineEdit && !e->text().isEmpty()) { // use keyboardSearch from the listView so we do not duplicate code view()->setCurrentIndex(d->currentIndex); view()->keyboardSearch(e->text()); if (view()->currentIndex().isValid() && view()->currentIndex() != d->currentIndex) newIndex = view()->currentIndex().row(); } } if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) { setCurrentIndex(newIndex); d->emitActivated(d->currentIndex); } else if (d->lineEdit) { d->lineEdit->event(e); }}/*! \reimp*/void QComboBox::keyReleaseEvent(QKeyEvent *e){ Q_D(QComboBox); if (d->lineEdit) d->lineEdit->event(e);}/*! \reimp*/#ifndef QT_NO_WHEELEVENTvoid QComboBox::wheelEvent(QWheelEvent *e){ Q_D(QComboBox); if (!d->viewContainer()->isVisible()) { int newIndex = currentIndex(); if (e->delta() > 0) --newIndex; else ++newIndex; if (newIndex >= 0 && newIndex < count()) { setCurrentIndex(newIndex); d->emitActivated(d->currentIndex); } e->accept(); }}#endif/*! \reimp*/void QComboBox::contextMenuEvent(QContextMenuEvent *e){ Q_D(QComboBox); if (d->lineEdit) { Qt::ContextMenuPolicy p = d->lineEdit->contextMenuPolicy(); d->lineEdit->setContextMenuPolicy(Qt::DefaultContextMenu); d->lineEdit->event(e); d->lineEdit->setContextMenuPolicy(p); }}/*! \reimp*/void QComboBox::inputMethodEvent(QInputMethodEvent *e){ Q_D(QComboBox); if (d->lineEdit) d->lineEdit->event(e);}/*! \reimp*/QVariant QComboBox::inputMethodQuery(Qt::InputMethodQuery query) const{ Q_D(const QComboBox); if (d->lineEdit) return d->lineEdit->inputMethodQuery(query); return QWidget::inputMethodQuery(query);}/*! \fn bool QComboBox::editable() const Use isEditable() instead.*//*! \fn void QComboBox::insertItem(const QPixmap &pixmap, int index) Use an insertItem() function that takes a QIcon instead, for example, insertItem(index, QIcon(pixmap)).*//*! \fn void QComboBox::insertItem(const QPixmap &pixmap, const QString &text, int index) Use an insertItem() function that takes a QIcon instead, for example, insertItem(index, QIcon(pixmap), text).*//*! \fn void QComboBox::changeItem(const QString &text, int index) Use setItemText() instead.*//*! \fn void QComboBox::changeItem(const QPixmap &pixmap, int index) Use setItemIcon() instead, for example, setItemIcon(index, QIcon(pixmap)).*//*! \fn void QComboBox::changeItem(const QPixmap &pixmap, const QString &text, int index) Use setItem() instead, for example, setItem(index, QIcon(pixmap),text).*//*! \fn void QComboBox::addItem(const QString &text, const QVariant &userData) Adds an item to the combobox with the given \a text, and containing the specified \a userData. The item is appended to the list of existing items.*//*! \fn void QComboBox::addItem(const QIcon &icon, const QString &text, const QVariant &userData) Adds an item to the combobox with the given \a icon and \a text, and containing the specified \a userData. The item is appended to the list of existing items.*//*! \fn void QComboBox::addItems(const QStringList &texts) Adds each of the strings in the given \a texts to the combobox. Each item is appended to the list of existing items in turn.*//*! \fn void QComboBox::editTextChanged(const QString &text) This signal is emitted when the text in the combobox's line edit widget is changed. The new text is specified by \a text.*//*! \fn QComboBox::InsertPolicy QComboBox::insertionPolicy() const \compat Use QComboBox::insertPolicy instead.*//*! \fn void QComboBox::setInsertionPolicy(InsertPolicy policy) \compat Use QComboBox::insertPolicy instead.*//*! \fn void QComboBox::setCurrentText(const QString &text) \compat Use setItemText() instead. \sa currentIndex()*//*! \fn QString QComboBox::text(int index) const \compat Use itemText() instead.*//*! \fn QPixmap QComboBox::pixmap(int index) const \compat Use itemIcon() instead.*//*! \fn void QComboBox::insertStringList(const QStringList &list, int index) \compat Use insertItems() instead.*//*! \fn void QComboBox::insertItem(const QString &text, int index) \compat*//*! \fn void QComboBox::clearEdit() \compat Use clearEditText() instead.*//*! \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -