Browse Source

Draggable label

Neal Wilson 11 years ago
parent
commit
04f55e69f5
1 changed files with 58 additions and 0 deletions
  1. 58
    0
      src/scales.w

+ 58
- 0
src/scales.w View File

@@ -0,0 +1,58 @@
1
+@** Collecting Measurements from Scales.
2
+
3
+\noindent When a computer connected scale is available, it can be useful to
4
+eliminate manual transcription from the data entry for batches. In general it
5
+is difficult to determine where a measurement should go automatically, but
6
+there are a number of situations where the ability to drag a measurement from a
7
+label and drop it to whatever input widget is appropriate would be a useful
8
+operation to support.
9
+
10
+To support this, we need to subclass |QLabel| to allow it to initiate a drag
11
+and drop operation.
12
+
13
+@(draglabel.h@>=
14
+#ifndef TypicaDragLabelInclude
15
+#define TypicaDragLabelInclude
16
+
17
+#include <QLabel>
18
+
19
+class DragLabel : public QLabel
20
+{
21
+	Q_OBJECT
22
+	public:
23
+		explicit DragLabel(const QString &labelText, QWidget *parent = NULL);
24
+	protected:
25
+		void mousePressEvent(QMouseEvent *event);
26
+};
27
+
28
+#endif
29
+
30
+@ The font size of the label is increased by default to make it easier to
31
+manipulate on a touch screen. Otherwise, there is little to do in this class.
32
+
33
+@(draglabel.cpp@>=
34
+#include "draglabel.h"
35
+
36
+#include <QDrag>
37
+#include <QMouseEvent>
38
+
39
+DragLabel::DragLabel(const QString &labelText, QWidget *parent) :
40
+	QLabel(labelText, parent)
41
+{
42
+	QFont labelFont = font();
43
+	labelFont.setPointSize(14);
44
+	setFont(labelFont);
45
+}
46
+
47
+void DragLabel::mousePressEvent(QMouseEvent *event)
48
+{
49
+	if(event->button() == Qt::LeftButton)
50
+	{
51
+		QDrag *drag = new QDrag(this);
52
+		QMimeData *mimeData = new QMimeData;
53
+		mimeData->setText(text());
54
+		drag->setMimeData(mimeData);
55
+		drag->exec();
56
+	}
57
+}
58
+

Loading…
Cancel
Save