Hello,
I have a problem here: i want to make an agenda, for that i want to make a context menu that is called on a day, but the right clic do not select the day under the cursor, for that reason i wanna simulate a left clic, for selecting the day under the cursor and then, call the context menu with the given selected day.
This is the code that I have:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "agenda.h"
namespace Ui {
class MainWindow;
}
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
Agenda *agenda;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "agenda.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
Agenda *agenda;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cc
#include "mainwindow.h"
#include "ui_mainwindow.h"
ui->setupUi(this);
agenda = new Agenda;
this->setCentralWidget(agenda);
}
MainWindow::~MainWindow() {
delete ui;
delete agenda;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
agenda = new Agenda;
this->setCentralWidget(agenda);
}
MainWindow::~MainWindow() {
delete ui;
delete agenda;
}
To copy to clipboard, switch view to plain text mode
agenda.h
#ifndef AGENDA_H
#define AGENDA_H
#include <QCalendarWidget>
#include <QMouseEvent>
Q_OBJECT
public:
explicit Agenda
(QWidget *parent
= 0);
signals:
public slots:
protected:
};
#endif // AGENDA_H
#ifndef AGENDA_H
#define AGENDA_H
#include <QCalendarWidget>
#include <QMouseEvent>
class Agenda : public QCalendarWidget {
Q_OBJECT
public:
explicit Agenda(QWidget *parent = 0);
signals:
public slots:
protected:
void mousePressEvent(QMouseEvent *event);
};
#endif // AGENDA_H
To copy to clipboard, switch view to plain text mode
agenda.cc
#include "agenda.h"
if(event->button() == Qt::RightButton) {
Agenda::mousePressEvent(&e);
}
Agenda::mousePressEvent(event);
}
#include "agenda.h"
Agenda::Agenda(QWidget *parent) : QCalendarWidget(parent) { }
void Agenda::mousePressEvent(QMouseEvent *event) {
if(event->button() == Qt::RightButton) {
QMouseEvent e(QMouseEvent::MouseButtonPress, event->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
Agenda::mousePressEvent(&e);
}
Agenda::mousePressEvent(event);
}
To copy to clipboard, switch view to plain text mode
it doesn't work, when I press the mouse's right button the day under the cursor keeps unselected
Please somebody help me
thanks very much
Bookmarks