QComboBox with custom tree view is not showing its items
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
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
{
Q_OBJECT
public:
explicit mainWindow
(QWidget *parent
= nullptr
);
~mainWindow();
signals:
public slots:
};
#endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "treecombobox.h"
#include <QStandardItem>
#include <QStandardItemModel>
#include <QList>
#include <QString>
{
QList<QStandardItem *> list;
list << item;
parentItem-> appendRow(list);
parentItem = item;
list.clear();
QList<QStandardItem *> list;
list << item;
parentItem->appendRow(list);
list.clear();
list << item2;
parentItem->appendRow(list);
TreeComboBox *t = new TreeComboBox(this);
t->setModel (& model);
t->expandAll();
}
mainWindow::~mainWindow(){
}
treecombobox.h
Code:
#ifndef TREECOMBOBOX_H
#define TREECOMBOBOX_H
#include <QComboBox>
#include <QTreeView>
#include <QWidget>
{
public:
TreeComboBox
(QWidget *parrent
= nullptr
);
void showPopup () override;
void hidePopup () override;
void hideColumn (int n);
void expandAll ();
private:
};
#endif // TREECOMBOBOX_H
treecombobox.cpp
Code:
#include "treecombobox.h"
#include <QHeaderView>
{
m_view
-> setFrameShape
(QFrame :: NoFrame);
m_view
-> setEditTriggers
(QTreeView :: NoEditTriggers);
m_view-> setAlternatingRowColors (true);
m_view
-> setSelectionBehavior
(QTreeView :: SelectRows);
m_view-> setRootIsDecorated (false);
m_view-> setWordWrap (true);
m_view-> setAllColumnsShowFocus (true);
m_view-> setItemsExpandable (false);
setView (m_view);
m_view-> header () -> setVisible (false);
}
void TreeComboBox :: hideColumn (int n)
{
m_view-> hideColumn (n);
}
void TreeComboBox :: expandAll ()
{
m_view-> expandAll ();
}
void TreeComboBox
:: selectIndex (const QModelIndex & index
) {
setRootModelIndex (index.parent ());
setCurrentIndex (index.row ());
m_view-> setCurrentIndex (index);
}
void TreeComboBox :: showPopup ()
{
}
void TreeComboBox :: hidePopup ()
{
setRootModelIndex (m_view-> currentIndex (). parent ());
setCurrentIndex (m_view-> currentIndex (). row ());
}
main.cpp
Code:
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char * argv[]){
mainWindow *w = new mainWindow();
w->resize(100, 100);
w->show();
return app.exec();
}
Re: QComboBox with custom tree view is not showing its items
How long do you think lives your model?
Re: QComboBox with custom tree view is not showing its items
And what I need to do?
Added after 19 minutes:
Quote:
Originally Posted by
INeedADollar
And what I need to do?
I found what is wrong. Thank you very much!