I have created the ComboBox widget like this:
cb.PNG

In addition to default QComboBox, it contains a custom clickable widget to the left of popup button. I pushed this widget as a child of QComboBox, but there is still one problem I cannot solve. I want this widget to be clickable while the popup is open, but the popup is closed when I press to thewidget's arrows, and the widget itself doesn't receive any mouse events. Is there any way to make this widget available for mouse events while the popup is active?

Here is the current combobox implementation:

CarMarksComboBox.h (the arrows widget is CarModelsSwitcher)
Qt Code:
  1. #pragma once
  2.  
  3. #include "VehiclesData.h"
  4. #include "widgets.h"
  5.  
  6. class CarMarksComboBox: public QComboBox
  7. {
  8. Q_OBJECT
  9. public:
  10. CarMarksComboBox(QWidget* parent = nullptr);
  11.  
  12. void init(const VehicleNamesMap& vehicleNamesMap);
  13.  
  14. bool eventFilter(QObject* obj, QEvent* ev) override;
  15. void showPopup() override;
  16. void hidePopup() override;
  17.  
  18. protected:
  19. void resizeEvent(QResizeEvent* event) override;
  20.  
  21. private:
  22. void updateArrowsWidgetPosition();
  23.  
  24. private:
  25. CarModelsSwitcher* m_carModelsSwitcher = nullptr;
  26. };
To copy to clipboard, switch view to plain text mode 

CarMarksComboBox.cpp
Qt Code:
  1. #include "CarMarksComboBox.h"
  2.  
  3. #include "CarMarksModel.h"
  4.  
  5. CarMarksComboBox::CarMarksComboBox(QWidget* parent)
  6. : QComboBox{parent}
  7. {
  8. }
  9.  
  10. void CarMarksComboBox::init(const VehicleNamesMap& vehicleNamesMap)
  11. {
  12. CarMarksModel* carMarksModel = new CarMarksModel(vehicleNamesMap);
  13. carMarksModel->setSelectionFacility(false);
  14.  
  15. QTreeView* carMarksView = new QTreeView;
  16. carMarksView->header()->setVisible(false);
  17. carMarksView->setMinimumHeight(300);
  18.  
  19. setView(carMarksView);
  20. setModel(carMarksModel);
  21.  
  22. m_carModelsSwitcher = new CarModelsSwitcher(this);
  23. m_carModelsSwitcher->installEventFilter(this);
  24. m_carModelsSwitcher->setVisible(false);
  25. }
  26.  
  27. bool CarMarksComboBox::eventFilter(QObject* obj, QEvent* ev)
  28. {
  29. if (obj == m_carModelsSwitcher && ev->type() == QEvent::Resize)
  30. updateArrowsWidgetPosition();
  31.  
  32. return QComboBox::eventFilter(obj, ev);
  33. }
  34.  
  35. void CarMarksComboBox::showPopup()
  36. {
  37. const CarMarksModel* carMarksModel = static_cast<const CarMarksModel*>(model());
  38. if (carMarksModel)
  39. {
  40. const int checkedModelsCount = carMarksModel->getCheckedModelsCount();
  41. if (checkedModelsCount > 0)
  42. {
  43. m_carModelsSwitcher->setText(QString::number(checkedModelsCount));
  44. m_carModelsSwitcher->setVisible(true);
  45. }
  46. }
  47.  
  48. QComboBox::showPopup();
  49. }
  50.  
  51. void CarMarksComboBox::hidePopup()
  52. {
  53. m_carModelsSwitcher->setVisible(false);
  54. QComboBox::hidePopup();
  55. }
  56.  
  57. void CarMarksComboBox::resizeEvent(QResizeEvent* event)
  58. {
  59. updateArrowsWidgetPosition();
  60.  
  61. QComboBox::resizeEvent(event);
  62. }
  63.  
  64. void CarMarksComboBox::updateArrowsWidgetPosition()
  65. {
  66. m_carModelsSwitcher->move(width() - m_carModelsSwitcher->width() - 28, (height() - m_carModelsSwitcher->height()) / 2);
  67. }
To copy to clipboard, switch view to plain text mode