mousePressEvent do not work
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
Code:
// 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();
}
Re: mousePressEvent do not work
If you want to do something with the right click you should subclass the contextMenuEvent(QContextMenuEvent *event)
Mywidget.h
Code:
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QtGui>
{
Q_OBJECT
public:
explicit MyWidget
(QWidget *parent
= 0);
protected:
public slots:
private:
};
#endif // MYWIDGET_H
MyWidget.cpp
Code:
#include <QMessageBox>
#include <QAction>
#include "mywidget.h"
MyWidget
::MyWidget(QWidget *parent
):{
setDate
(QDate(1977,
2,
15));
actionNew
= new QAction(tr
("Do Something New"),
this);
// connect(actionNew, SIGNAL(triggered()), this, SLOT(DoSomethingNew()));
}
{
menuRight.addAction(actionNew);
menuRight.exec(event->globalPos());
}
NOTE: this code replaces the default context menu
Re: mousePressEvent do not work
Hi Rhayader, hi rest
thanks for this hint.
In the meantime i found out why the mouseevents do not work as i expected.
Actually they work but not for the edit field (QlineEdit) they work for the QSpinBox.
If one click on the arrow the are called.
Two additional questions :
1. How to overwrite the QLineEdit mouseevent methods.
2. How can I access the 'original' menue to add the action there instead of creatin a new menu.
Thanks and have fun
Dexli