源码中的例子
QStyleOptionComboBox optCombo;optCombo.init(this);optCombo.editable = true;optCombo.subControls = QStyle::SC_All;if(QStyle::SC_ComboBoxArrow == this->style()->hitTestComplexControl(QStyle::CC_ComboBox, &optCombo, event->pos(), this)) {
源码获取下拉窗口的位置
void QDateTimeEditPrivate::positionCalendarPopup()
{Q_Q(QDateTimeEdit);QPoint pos = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().bottomRight() : q->rect().bottomLeft();QPoint pos2 = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().topRight() : q->rect().topLeft();pos = q->mapToGlobal(pos);pos2 = q->mapToGlobal(pos2);QSize size = monthCalendar->sizeHint();QRect screen = QApplication::desktop()->availableGeometry(pos);//handle popup falling "off screen"if (q->layoutDirection() == Qt::RightToLeft) {pos.setX(pos.x()-size.width());pos2.setX(pos2.x()-size.width());if (pos.x() < screen.left())pos.setX(qMax(pos.x(), screen.left()));else if (pos.x()+size.width() > screen.right())pos.setX(qMax(pos.x()-size.width(), screen.right()-size.width()));} else {if (pos.x()+size.width() > screen.right())pos.setX(screen.right()-size.width());pos.setX(qMax(pos.x(), screen.left()));}if (pos.y() + size.height() > screen.bottom())pos.setY(pos2.y() - size.height());else if (pos.y() < screen.top())pos.setY(screen.top());if (pos.y() < screen.top())pos.setY(screen.top());if (pos.y()+size.height() > screen.bottom())pos.setY(screen.bottom()-size.height());monthCalendar->move(pos);
}