В Qt есть очень универсальный способ, позволяющий обработать клик практически на любом элементе формы, у которого даже нет сигнала clicked(). Если вы имеете дело с производным от класса QWidget достаточно реализовать приватную, виртуальную функцию

mousePressEvent, которая имеет вот такой прототип:

void mousePressEvent ( QMouseEvent * event );

К примеру, вы используете библиотеку QWT для графиков и хотите, чтобы по клику на графике открывалось окно с более подробными данными. Необходимо создать такую обёртку:

Файл plot.h:

  1. #ifndef PLOT_H 
  2. #define PLOT_H
  3.        
  4. #include "qwt_plot.h"
  5.        
  6. class plot : public QwtPlot
  7. {
  8.     Q_OBJECT
  9. public:
  10.     explicit plot(QWidget *parent = 0);
  11.        
  12. private:       
  13.     void mousePressEvent ( QMouseEvent * event );      
  14. signals:         
  15.        
  16. public slots:  
  17. };

Файл plot.cpp:

  1. #include "plot.h"
  2. #include "flypage.h"
  3.  
  4. plot::plot(QWidget *parent) :
  5.     QwtPlot(parent)
  6. {
  7. }
  8.  
  9. void plot::mousePressEvent (QMouseEvent *event)
  10. {
  11.     // do not firing any event besides code below becose event allready handled
  12.     event->accept();
  13.  
  14.     QMap<QString, QString> pmap;
  15.     pmap.insert ("tempPlot", "temp");
  16.     pmap.insert ("humPlot", "humidity");
  17.     pmap.insert ("pressPlot", "pressure");
  18.     QString flyPageMode;
  19.     flyPageMode = pmap [objectName()];
  20.  
  21.     if (!flyPageMode.isEmpty())
  22.     {
  23.         flyPage *fp = new flyPage;
  24.         fp->setRenderMode (flyPageMode);
  25.         // talking QDialog not store window after close() method
  26.         fp->setAttribute( Qt::WA_DeleteOnClose );
  27.         fp->fdata->get();
  28.         fp->show();
  29.     }
  30.  
  31. }

Поговорим о приведённом коде обёртки для виджета QwtPlot. Обратите внимание на первую строчку под комментарием - таким образом мы даём понять, что нас не интересуют никакие действия, которые могли бы быть определены у виджета по-умолчанию. Такое поведение может быть не всегда ожидаемым, и в некоторых случаях было бы резонно вызвать код, который замещается данным классом, естественно передав ему перехваченный event:

QwtPlot::mousePressEvent(event);

Кстати event имеет функцию pos(), через которую можно узнать координаты клика.

Вообще говоря о событиях Qt, стоит отметить, что случившийся Event "распространяется" по всем возможным инстанциям. У вас могут быть веские причины вызвать event->ignore(), чтобы event пролетел мимо вашего обработчика и достиг какого-нибудь другого. Полезно, в случае если вы добавляете что-то своё, к уже существующему функционалу виджета.

Так же существуют event-функции, возвращающие bool значение, в зависимости от которого определяется обработан event или нет (true - обработан, false - нет).

Более подробные сведения вы найдёте в документации.



Нет аватара

Drywallive 24 Februarя в 22:10 #

manuscripts underwent in the Middle

Нет аватара

Drywallive 24 Februarя в 22:10 #

manuscripts underwent in the Middle

Нет аватара

dorthyiz1 01 Apriя в 23:00 #

Miss catherine bell nude playboy hairy porn pictures kyiv-hayli.hotnatalia.com/?juliana-cristal free porn dicks bareback big brother lea walker porn free gay dad porn first time hardcore lesbian free porn jessica dee life after porn

Нет аватара

dorthyiz1 01 Apriя в 23:00 #

Miss catherine bell nude playboy hairy porn pictures kyiv-hayli.hotnatalia.com/?juliana-cristal free porn dicks bareback big brother lea walker porn free gay dad porn first time hardcore lesbian free porn jessica dee life after porn

Нет аватара

Yamahahxo 03 Apriя в 09:24 #

only a few survived.

Нет аватара

Yamahahxo 03 Apriя в 09:24 #

only a few survived.

Нет аватара

stevennx69 02 Maя в 16:57 #

Sick elderly porn videos elderly couples granny mommy taylor-rain-college.hotblognetwork.com/?bria-joann... porn passwords in spanish i fucked my mom porn thumbnail movies porn kidie porn hard core gothic lesbians porn

Нет аватара

stevennx69 02 Maя в 16:57 #

Sick elderly porn videos elderly couples granny mommy taylor-rain-college.hotblognetwork.com/?bria-joann... porn passwords in spanish i fucked my mom porn thumbnail movies porn kidie porn hard core gothic lesbians porn

Нет аватара

PhillipForge 29 Maя в 22:25 #

London CNN — Opposite a bed in central London, light filters through a stained-glass window depicting, in fragments of copper and blue, Jesus Christ. blacksprut Three people have lived in the deserted cathedral in the past two years, with each occupant — an electrician, a sound engineer and a journalist — paying a monthly fee to live in the priest’s quarters. блэк спрут ссылка The cathedral is managed by Live-in Guardians, a company finding occupants for disused properties, including schools, libraries and pubs, across Britain. The residents — so-called property guardians — pay a fixed monthly “license fee,” which is usually much lower than the typical rent in the same area. blackspfgh3bi6im374fgl54qliir6to37txpkkd6ucfiu7whf... Applications to become guardians are going “through the roof,” with more people in their late thirties and forties signing on than in the past, said Arthur Duke, the founder and managing director of Live-in Guardians. зеркала блэк спрут “That’s been brought about by the cost-of-living crisis,” he said. “People are looking for cheaper ways to live.” blacksprut bs2sprut.com

Нет аватара

PhillipForge 29 Maя в 22:25 #

London CNN — Opposite a bed in central London, light filters through a stained-glass window depicting, in fragments of copper and blue, Jesus Christ. blacksprut Three people have lived in the deserted cathedral in the past two years, with each occupant — an electrician, a sound engineer and a journalist — paying a monthly fee to live in the priest’s quarters. блэк спрут ссылка The cathedral is managed by Live-in Guardians, a company finding occupants for disused properties, including schools, libraries and pubs, across Britain. The residents — so-called property guardians — pay a fixed monthly “license fee,” which is usually much lower than the typical rent in the same area. blackspfgh3bi6im374fgl54qliir6to37txpkkd6ucfiu7whf... Applications to become guardians are going “through the roof,” with more people in their late thirties and forties signing on than in the past, said Arthur Duke, the founder and managing director of Live-in Guardians. зеркала блэк спрут “That’s been brought about by the cost-of-living crisis,” he said. “People are looking for cheaper ways to live.” blacksprut bs2sprut.com


Войдите или зарегистрируйтесь, чтобы написать комментарий.