Hi i want make CustomContextMenu in reimplement QTreeView , but i have done somting wrong ;(
.h
#ifndef MYTREEVIEW_H
#define MYTREEVIEW_H
#include <QtGui>
#include <QtCore>
{
Q_OBJECT
public:
explicit MyTreeView
(QWidget *parent
= 0);
signals:
public slots:
void slotCustomContextMenu
(QPoint &point
);
void slotTest();
};
#endif // MYTREEVIEW_H
#ifndef MYTREEVIEW_H
#define MYTREEVIEW_H
#include <QtGui>
#include <QtCore>
class MyTreeView : public QTreeView
{
Q_OBJECT
public:
explicit MyTreeView(QWidget *parent = 0);
signals:
public slots:
void slotCustomContextMenu(QPoint &point);
void slotTest();
};
#endif // MYTREEVIEW_H
To copy to clipboard, switch view to plain text mode
.cpp
#include "mytreeview.h"
MyTreeView
::MyTreeView(QWidget *parent
) :{
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this,
SIGNAL(customContextMenuRequested
(QPoint &point
)),
this,
SLOT(slotCustomContextMenu
(QPoint &point
)));
}
void MyTreeView
::slotCustomContextMenu(QPoint &point
) {
QString fileName
= this
->model
()->data
(this
->model
()->index
(index.
row(),
0),
0).
toString();
menu
->addAction
(QString("Import"),
this,
SLOT(slotTest
()));
menu
->addAction
(QString("Export"),
this,
SLOT(slotTest
()));
}
void MyTreeView::slotTest()
{
}
#include "mytreeview.h"
MyTreeView::MyTreeView(QWidget *parent) :
QTreeView(parent)
{
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this,SIGNAL(customContextMenuRequested(QPoint &point)), this, SLOT(slotCustomContextMenu(QPoint &point)));
}
void MyTreeView::slotCustomContextMenu(QPoint &point)
{
QMenu *menu = new QMenu;
QModelIndex index = this->currentIndex();
QString fileName = this->model()->data(this->model()->index(index.row(), 0),0).toString();
menu->addAction(QString("Import"), this, SLOT(slotTest()));
menu->addAction(QString("Export"), this, SLOT(slotTest()));
menu->exec(QCursor::pos());
}
void MyTreeView::slotTest()
{
}
To copy to clipboard, switch view to plain text mode
treeview work but right click dont show menu ;( some advice ??
Bookmarks