问题
In Qt QComboBox, there is no clicked signal to get the slot to override. But I need to fill the combo box items dynamically. That is, I need to check the items and renew the combo box all items list (when user changes other items should have impact on the list).
回答1:
For this complicated issue, we can use event filter method in qt. Try to return false for all action to make the further process taken place.
bool QtMyWindow::eventFilter(QObject *f_object, QEvent *f_event){
if(f_object == ui->comboBoxResetValue){
if(f_event->type() == QEvent::MouseButtonPress){
fillItems(); // try to clear before fill to avoid repetitions
}
return false;
}
return false;
}
and we also inform the object that we are going to filter the event for you, so in constructor, include this line
QtMyWindow::QtMyWindow(QObject* parent,...)
{
...
ui->comboBox->installEventFilter(this);
}
来源:https://stackoverflow.com/questions/33773368/mouse-press-slot-for-qcombobox-fill-the-items-dynamically-if-user-clicks-the-c