Created
August 10, 2010 15:23
-
-
Save anonymous/517445 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "calendar.h" | |
Calendar::Calendar(QWidget *parent) : | |
QWidget(parent) | |
{ | |
qCal = new QCalendarWidget; | |
qBtn = new QPushButton(tr("Press me")); | |
connect(qBtn, SIGNAL(clicked()), this, SLOT(testCustomClick())); | |
QVBoxLayout *layout = new QVBoxLayout; | |
layout->addWidget(qCal); | |
layout->addWidget(qBtn); | |
setLayout(layout); | |
qDebug() << "Date:" << QDate::currentDate(); | |
} | |
Calendar::~Calendar() | |
{ | |
} | |
void Calendar::testCustomClick() | |
{ | |
QMouseEvent qm2(QEvent::MouseButtonPress, QPoint(qCal->width()/2,qCal->height()/2), Qt::LeftButton , Qt::LeftButton, Qt::NoModifier); | |
QApplication::sendEvent(qCal, &qm2); | |
qDebug() << "isAccepted: " << qm2.isAccepted(); //prints False | |
} | |
void Calendar::mousePressEvent(QMouseEvent* ev) | |
{ | |
qDebug() << "mouse event: " << ev << "x=" << ev->x() <<" y=" << ev->y(); | |
QWidget::mousePressEvent(ev); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef CALENDAR_H | |
#define CALENDAR_H | |
#include <QtGui> | |
class Calendar : public QWidget | |
{ | |
Q_OBJECT | |
public: | |
explicit Calendar(QWidget *parent = 0); | |
~Calendar(); | |
private slots: | |
void testCustomClick(); | |
private: | |
QCalendarWidget *qCal; | |
QPushButton *qBtn; | |
protected: | |
virtual void mousePressEvent(QMouseEvent *); | |
}; | |
#endif // CALENDAR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtGui/QApplication> | |
#include "calendar.h" | |
int main(int argc, char *argv[]) | |
{ | |
QApplication a(argc, argv); | |
Calendar cal; | |
cal.show(); | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment