Hello! I try to make a QComboBox with custom tree view, but combo box is not showing its items when clicking on it. Can you help me please?

My code:

mainWindow.h

Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QWidget>
  5.  
  6. class mainWindow : public QWidget
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit mainWindow(QWidget *parent = nullptr);
  11. ~mainWindow();
  12.  
  13. signals:
  14.  
  15. public slots:
  16. };
  17.  
  18. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "treecombobox.h"
  3. #include <QStandardItem>
  4. #include <QStandardItemModel>
  5. #include <QList>
  6. #include <QString>
  7.  
  8. mainWindow::mainWindow(QWidget *parent) : QWidget(parent)
  9. {
  10. QStandardItem * parentItem = model.invisibleRootItem ();
  11. QStandardItem * item = new QStandardItem (QString ("item 0");
  12. QList<QStandardItem *> list;
  13. list << item;
  14. parentItem-> appendRow(list);
  15.  
  16. parentItem = item;
  17. QStandardItem * item = new QStandardItem (QString ("item 1") ;
  18. list.clear();
  19. QList<QStandardItem *> list;
  20. list << item;
  21. parentItem->appendRow(list);
  22. list.clear();
  23. QStandardItem * item2 = new QStandardItem (QString ("item 2");
  24. list << item2;
  25. parentItem->appendRow(list);
  26. TreeComboBox *t = new TreeComboBox(this);
  27. t->setModel (& model);
  28. t->expandAll();
  29. }
  30.  
  31. mainWindow::~mainWindow(){
  32.  
  33. }
To copy to clipboard, switch view to plain text mode 

treecombobox.h
Qt Code:
  1. #ifndef TREECOMBOBOX_H
  2. #define TREECOMBOBOX_H
  3.  
  4. #include <QComboBox>
  5. #include <QTreeView>
  6. #include <QWidget>
  7.  
  8. class TreeComboBox final: public QComboBox
  9. {
  10. public:
  11. TreeComboBox (QWidget *parrent = nullptr);
  12. void showPopup () override;
  13. void hidePopup () override;
  14. void hideColumn (int n);
  15. void expandAll ();
  16. void selectIndex (const QModelIndex & index);
  17. private:
  18. QTreeView * m_view = nullptr;
  19. };
  20.  
  21. #endif // TREECOMBOBOX_H
To copy to clipboard, switch view to plain text mode 

treecombobox.cpp
Qt Code:
  1. #include "treecombobox.h"
  2. #include <QHeaderView>
  3.  
  4. TreeComboBox :: TreeComboBox (QWidget *parent) : QComboBox(parent)
  5. {
  6. m_view = new QTreeView;
  7. m_view-> setFrameShape (QFrame :: NoFrame);
  8. m_view-> setEditTriggers (QTreeView :: NoEditTriggers);
  9. m_view-> setAlternatingRowColors (true);
  10. m_view-> setSelectionBehavior (QTreeView :: SelectRows);
  11. m_view-> setRootIsDecorated (false);
  12. m_view-> setWordWrap (true);
  13. m_view-> setAllColumnsShowFocus (true);
  14. m_view-> setItemsExpandable (false);
  15. setView (m_view);
  16. m_view-> header () -> setVisible (false);
  17. }
  18.  
  19. void TreeComboBox :: hideColumn (int n)
  20. {
  21. m_view-> hideColumn (n);
  22. }
  23.  
  24. void TreeComboBox :: expandAll ()
  25. {
  26. m_view-> expandAll ();
  27. }
  28.  
  29. void TreeComboBox :: selectIndex (const QModelIndex & index)
  30. {
  31. setRootModelIndex (index.parent ());
  32. setCurrentIndex (index.row ());
  33. m_view-> setCurrentIndex (index);
  34. }
  35.  
  36. void TreeComboBox :: showPopup ()
  37. {
  38. setRootModelIndex (QModelIndex ());
  39. QComboBox :: showPopup ();
  40. }
  41.  
  42. void TreeComboBox :: hidePopup ()
  43. {
  44. setRootModelIndex (m_view-> currentIndex (). parent ());
  45. setCurrentIndex (m_view-> currentIndex (). row ());
  46. QComboBox :: hidePopup ();
  47. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include <QApplication>
  2. #include "mainwindow.h"
  3.  
  4. int main(int argc, char * argv[]){
  5. QApplication app(argc, argv);
  6. mainWindow *w = new mainWindow();
  7. w->resize(100, 100);
  8. w->show();
  9. return app.exec();
  10. }
To copy to clipboard, switch view to plain text mode