Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
qclickablelabel.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef qclickablelabel_h
14 #define qclickablelabel_h
15 
17 #include <QLabel>
18 
19 #include <map>
20 #include <vector>
21 
22 #include <mitkCommon.h>
23 
36 {
37  Q_OBJECT
38 
39 public:
45  QClickableLabel(QWidget *parent, Qt::WindowFlags f = {});
46 
53  QClickableLabel(const QString &text, QWidget *parent, Qt::WindowFlags f = {});
54 
56  ~QClickableLabel() override;
57 
63  void AddHotspot(const QString &name, const QRect position);
64 
69  void RemoveHotspot(const QString &name);
70 
75  void RemoveHotspot(unsigned int hotspotIndex);
76 
79 
80 signals:
85  void mousePressed(const QString &hotspotName);
86 
91  void mousePressed(unsigned int hotspotIndex);
92 
97  void mouseReleased(const QString &hotspotName);
98 
103  void mouseReleased(unsigned int hotspotIndex);
104 
105 protected:
106  void mousePressEvent(QMouseEvent *e) override;
107  void mouseReleaseEvent(QMouseEvent *e) override;
108 
110  unsigned int matchingRect(const QPoint &p);
111 
112  typedef std::vector<QRect> RectVectorType;
114 
115  typedef std::map<QString, unsigned int> NameToIndexMapType;
116  typedef std::map<unsigned int, QString> IndexToNameMapType;
119 };
120 
121 #endif
#define MITKQTWIDGETSEXT_EXPORT
A QLabel with named rectangular hotspots that emit signals when clicked.
void mouseReleaseEvent(QMouseEvent *e) override
IndexToNameMapType m_HotspotNameForIndex
std::vector< QRect > RectVectorType
std::map< unsigned int, QString > IndexToNameMapType
void RemoveHotspot(const QString &name)
Remove a hotspot by name.
QClickableLabel(QWidget *parent, Qt::WindowFlags f={})
Construct a clickable label.
QClickableLabel(const QString &text, QWidget *parent, Qt::WindowFlags f={})
Construct a clickable label with initial text.
std::map< QString, unsigned int > NameToIndexMapType
NameToIndexMapType m_HotspotIndexForName
void mousePressed(const QString &hotspotName)
Emitted on mouse press within a hotspot (by name).
void mousePressEvent(QMouseEvent *e) override
void mousePressed(unsigned int hotspotIndex)
Emitted on mouse press within a hotspot (by index).
void RemoveAllHotspots()
Remove all hotspots.
~QClickableLabel() override
Destructor.
void mouseReleased(const QString &hotspotName)
Emitted on mouse release within a hotspot (by name).
RectVectorType m_Hotspots
void RemoveHotspot(unsigned int hotspotIndex)
Remove a hotspot by index.
void AddHotspot(const QString &name, const QRect position)
Add a named hotspot at the given rectangle position.
unsigned int matchingRect(const QPoint &p)
returns index == m_Hotspots.size() if nothing is hit
void mouseReleased(unsigned int hotspotIndex)
Emitted on mouse release within a hotspot (by index).