1
votes

I have implemented a QTreeview with QAbstractItemModel how can i be notified if i click on the tree view item with left mouse click.Do we have any function like OnLButtonDown() avalible for the tree view.

WavefrontRenderer::WavefrontRenderer(TreeModel* model , QWidget *parent) : 
QMainWindow(parent)
 {
    setupUi(this);  
    treeView->setModel(model);
    treeView->setDragEnabled(true);
    treeView->setAcceptDrops(true);
    treeView->installEventFilter(this);   
    connect(pushButtonAddGroup, SIGNAL(clicked()), this, SLOT(insertRow()));
     connect(pushButtonAddChild , SIGNAL(clicked()), this, 
    SLOT(insertChild()));
    connect(pushButtonDeleteGroup , SIGNAL(clicked()), this, 
    SLOT(removeRow()));
    connect( ButtonSphere, SIGNAL(clicked()), this, SLOT(AddSphere()));
    connect(treeView , SIGNAL(clicked()), this, SLOT(message()));   
 }

I tried to connect the treeview to clicked slot but this did not work for me.

Since i am new to qt i am not sure if we connect the treeview same way as we connect buttons to the clicked slots.

1
You have the clicked sginal.thuga
How can i connect it to treeview ?user8028736
i tried connect(treeView , SIGNAL(clicked()), this, SLOT(message()));user8028736
did not work for me.user8028736
Please edit your question to show the code you've tried so far and explain more clearly what you're trying to achieve.G.M.

1 Answers

1
votes

You should always check your connections:

bool ok = connect(...);
Q_ASSERT(ok);

If you do that, you'll find that connecting to the clicked() signal doesn't work.

If you then take a look at your error console you'll see a Qt message that the signal clicked() is not found in QTreeView.
That's because the parameters need to be included in the SIGNAL(...) macro.

Either put them there but just the type without the parameter name:

bool ok = connect(treeView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(message()));

or avoid this pitfall by using the new connect syntax:

bool ok = connect(treeView, &QAbstractItemView::clicked, this, &WavefrontRenderer::message);

This will give you a compiler error if the signal or slot doesn't exist.