@@ -65,6 +65,13 @@ alertwidget::alertwidget(int msecs, const QString& name, bool turnedOn, QWidget
6565 << QTime::currentTime ().hour () <<" :" << QTime::currentTime ().minute () << std::endl;
6666 alertTick.start (calculateDuration (alertTime));
6767 }
68+
69+
70+ this ->setContextMenuPolicy (Qt::CustomContextMenu);
71+
72+ connect (this , SIGNAL (customContextMenuRequested (const QPoint &)),
73+ this , SLOT (ShowContextMenu (const QPoint &)));
74+
6875}
6976
7077alertwidget::~alertwidget ()
@@ -158,14 +165,34 @@ void alertwidget::closeAlarm()
158165 this ->close ();
159166}
160167
168+ void alertwidget::changeAlarm ()
169+ {
170+
171+ }
172+
173+ void alertwidget::ShowContextMenu (const QPoint &pos)
174+ {
175+ QMenu contextMenu (tr (" Context menu" ), this );
176+
177+ QAction action1 (" Delete alarm" , this );
178+ QAction action2 (" Change alarm" , this );
179+ connect (&action1, SIGNAL (triggered ()), this , SLOT (closeAlarm ()));
180+ connect (&action2, SIGNAL (triggered ()), this , SLOT (changeAlarm ()));
181+ contextMenu.addAction (&action1);
182+ contextMenu.addAction (&action2);
183+
184+ contextMenu.exec (mapToGlobal (pos));
185+ }
186+
161187
162188void alertwidget::mousePressEvent (QMouseEvent *e)
163189{
164190 if (e->button () == Qt::RightButton)
165191 {
166192 player->stop ();
167193
168- emit closeAlarm ();
194+ ShowContextMenu (e->pos ());
195+ // emit closeAlarm();
169196 }
170197}
171198
0 commit comments