Skip to content

Instantly share code, notes, and snippets.

Created August 10, 2010 15:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/517445 to your computer and use it in GitHub Desktop.
Save anonymous/517445 to your computer and use it in GitHub Desktop.
#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);
}
#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
#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