Hi all,
I fail to get the mousePressEvent working for QDateEdit.
If the right button is clicked a menue shows up. Is there a way to setup my one menue for this ? (add items at least)
Thanks
Dexli
// Mywidget.h
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QtGui>
{
Q_OBJECT
public:
explicit MyWidget
(QWidget *parent
= 0);
protected:
public slots:
};
#endif // MYWIDGET_H
// MyWidget.cpp
#include <QMessageBox>
#include "mywidget.h"
MyWidget
::MyWidget(QWidget *parent
):{
setDate
(QDate(1977,
2,
15));
}
{
box->setText("Button geklickt");
box->show();
};
// Main.cpp
#include <QtGui>
#include "mywidget.h"
int main(int argc, char *argv[])
{
MyWidget* dateed = new MyWidget(&window);
layout->addWidget(dateed);
window.show();
return app.exec();
}
// Mywidget.h
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QtGui>
class MyWidget : public QDateEdit
{
Q_OBJECT
public:
explicit MyWidget(QWidget *parent = 0);
protected:
virtual void mousePressEvent ( QMouseEvent * event ) ;
public slots:
};
#endif // MYWIDGET_H
// MyWidget.cpp
#include <QMessageBox>
#include "mywidget.h"
MyWidget::MyWidget(QWidget *parent ):
QDateEdit(parent)
{
setDate(QDate(1977,2,15));
}
void MyWidget::mousePressEvent ( QMouseEvent * event )
{
QMessageBox *box = new QMessageBox();
box->setText("Button geklickt");
box->show();
};
// Main.cpp
#include <QtGui>
#include "mywidget.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
MyWidget* dateed = new MyWidget(&window);
QHBoxLayout* layout = new QHBoxLayout(&window);
layout->addWidget(dateed);
window.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks