Обработка клика по объекту формы в Qt
В Qt есть очень универсальный способ, позволяющий обработать клик практически на любом элементе формы, у которого даже нет сигнала clicked(). Если вы имеете дело с производным от класса QWidget достаточно реализовать приватную, виртуальную функцию
mousePressEvent, которая имеет вот такой прототип:
К примеру, вы используете библиотеку QWT для графиков и хотите, чтобы по клику на графике открывалось окно с более подробными данными. Необходимо создать такую обёртку:
Файл plot.h:
- #ifndef PLOT_H
- #define PLOT_H
- #include "qwt_plot.h"
- class plot : public QwtPlot
- {
- Q_OBJECT
- public:
- private:
- signals:
- public slots:
- };
Файл plot.cpp:
- #include "plot.h"
- #include "flypage.h"
- QwtPlot(parent)
- {
- }
- {
- // do not firing any event besides code below becose event allready handled
- event->accept();
- pmap.insert ("tempPlot", "temp");
- pmap.insert ("humPlot", "humidity");
- pmap.insert ("pressPlot", "pressure");
- QString flyPageMode;
- flyPageMode = pmap [objectName()];
- if (!flyPageMode.isEmpty())
- {
- flyPage *fp = new flyPage;
- fp->setRenderMode (flyPageMode);
- // talking QDialog not store window after close() method
- fp->fdata->get();
- fp->show();
- }
- }
Поговорим о приведённом коде обёртки для виджета QwtPlot. Обратите внимание на первую строчку под комментарием - таким образом мы даём понять, что нас не интересуют никакие действия, которые могли бы быть определены у виджета по-умолчанию. Такое поведение может быть не всегда ожидаемым, и в некоторых случаях было бы резонно вызвать код, который замещается данным классом, естественно передав ему перехваченный 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