-------------------------------------------------------------------------
| 435 | |
| 436 | // ------------------------------------------------------------------------- |
| 437 | void ctkMenuComboBox::setEditableBehavior(ctkMenuComboBox::EditableBehavior edit) |
| 438 | { |
| 439 | Q_D(ctkMenuComboBox); |
| 440 | d->EditBehavior = edit; |
| 441 | this->disconnect(d->MenuComboBox, SIGNAL(popupShown()), |
| 442 | d, SLOT(setComboBoxEditable())); |
| 443 | switch (edit) |
| 444 | { |
| 445 | case ctkMenuComboBox::Editable: |
| 446 | d->MenuComboBox->setContextMenuPolicy(Qt::DefaultContextMenu); |
| 447 | d->setComboBoxEditable(true); |
| 448 | break; |
| 449 | case ctkMenuComboBox::NotEditable: |
| 450 | d->MenuComboBox->setContextMenuPolicy(Qt::DefaultContextMenu); |
| 451 | d->setComboBoxEditable(false); |
| 452 | break; |
| 453 | case ctkMenuComboBox::EditableOnFocus: |
| 454 | d->setComboBoxEditable(this->hasFocus()); |
| 455 | // Here we set the context menu policy to fix a crash on the right click. |
| 456 | // Opening the context menu removes the focus on the line edit, |
| 457 | // the comboBox becomes not editable, and the line edit is deleted. |
| 458 | // The opening of the context menu is done in the line edit and lead to |
| 459 | // a crash because it infers that the line edit is valid. Another fix |
| 460 | // could be to delete the line edit later (deleteLater()). |
| 461 | d->MenuComboBox->setContextMenuPolicy(Qt::NoContextMenu); |
| 462 | break; |
| 463 | case ctkMenuComboBox::EditableOnPopup: |
| 464 | d->setComboBoxEditable(false); |
| 465 | this->connect(d->MenuComboBox, SIGNAL(popupShown()), |
| 466 | d, SLOT(setComboBoxEditable())); |
| 467 | // Same reason as in ctkMenuComboBox::EditableOnFocus. |
| 468 | d->MenuComboBox->setContextMenuPolicy(Qt::NoContextMenu); |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | // ------------------------------------------------------------------------- |
| 474 | ctkMenuComboBox::EditableBehavior ctkMenuComboBox::editableBehavior()const |