hi all,
i've made a dll to provide some table functions ( excel like ) to my main project. It works fine with linkage and all. The code to make context menu and calling it is also in the dll part, in the constructor.
My problem is, in my table in the main project, i get context menu at all places, except at the headers. Like in excel on right click on the headers select all rows/columns and giv a context menu there also. My context menu is not coming on the header.
what can be the problem.
below is my dll code:
//QGrid.cpp
#include <QtGui>
#include "QGrid.h"
#include <QMessageBox>
{
createActions();
setUpContextMenu();
}
{
createActions();
setUpContextMenu();
}
void QGrid::setUpContextMenu()
{
addAction(copyAct);
addAction(pasteAct);
...
setContextMenuPolicy(Qt::ActionsContextMenu);
}
void QGrid::createActions()
{
copyAct
= new QAction(QIcon(":/images/copy.png"),
"&Copy",
this);
copyAct->setShortcut(tr("Ctrl+C"));
copyAct->setStatusTip(tr("Copy the current selection's contents to the "
"clipboard"));
connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));
pasteAct
= new QAction(QIcon(":/images/paste.png"),
"&Paste",
this);
pasteAct->setShortcut(tr("Ctrl+V"));
pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
"selection"));
connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste()));
....
}
//QGrid.cpp
#include <QtGui>
#include "QGrid.h"
#include <QMessageBox>
QGrid::QGrid(int r, int c,QWidget *parent) : QTableWidget(r,c,parent)
{
createActions();
setUpContextMenu();
}
QGrid::QGrid(QWidget *parent) : QTableWidget(parent)
{
createActions();
setUpContextMenu();
}
void QGrid::setUpContextMenu()
{
addAction(copyAct);
addAction(pasteAct);
...
setContextMenuPolicy(Qt::ActionsContextMenu);
}
void QGrid::createActions()
{
copyAct = new QAction(QIcon(":/images/copy.png"), "&Copy", this);
copyAct->setShortcut(tr("Ctrl+C"));
copyAct->setStatusTip(tr("Copy the current selection's contents to the "
"clipboard"));
connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));
pasteAct = new QAction(QIcon(":/images/paste.png"), "&Paste", this);
pasteAct->setShortcut(tr("Ctrl+V"));
pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
"selection"));
connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste()));
....
}
To copy to clipboard, switch view to plain text mode
//QGrid.h
#ifndef QGRID_H
#define QGRID_H
#include <QtCore/qglobal.h>
#include <QtGui/QDialog>
#include <QAction>
#include <QTableWidget>
#ifdef BUILD_QGRID
# ifdef Q_CC_MSVC
# define QGRID_EXPORT Q_DECL_EXPORT
# else
# define QGRID_EXPORT Q_DECL_IMPORT
# endif
#else
# define QGRID_EXPORT
#endif
{
Q_OBJECT
public:
QGrid
(int c,
int r,
QWidget *parent
= 0);
private:
....
public slots:
void copy();
void paste();
....
public:
void setUpContextMenu();
void createActions();
};
#endif
//QGrid.h
#ifndef QGRID_H
#define QGRID_H
#include <QtCore/qglobal.h>
#include <QtGui/QDialog>
#include <QAction>
#include <QTableWidget>
#ifdef BUILD_QGRID
# ifdef Q_CC_MSVC
# define QGRID_EXPORT Q_DECL_EXPORT
# else
# define QGRID_EXPORT Q_DECL_IMPORT
# endif
#else
# define QGRID_EXPORT
#endif
class QGRID_EXPORT QGrid : public QTableWidget
{
Q_OBJECT
public:
QGrid(int c,int r,QWidget *parent = 0);
QGrid(QWidget *parent = 0);
QClipboard *clip;
QTableWidget *table;
private:
QAction *copyAct;
QAction *pasteAct;
....
public slots:
void copy();
void paste();
....
public:
void setUpContextMenu();
void createActions();
};
#endif
To copy to clipboard, switch view to plain text mode
please help ....
Bookmarks