Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkSimpleTextOverlayWidget.cpp
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 
14 
15 #include "QTextDocument"
16 #include "QPainter"
17 #include "QApplication"
18 
20  : QmitkOverlayWidget(parent)
21 {
22 }
23 
25 {
26 }
27 
29 {
30  return m_Text;
31 }
32 
34 {
35  m_Text = text;
36  this->update();
37 }
38 
40 {
42 
43  auto styleSheet = qApp->styleSheet();
44 
45  QPainter painter(this);
46  QTextDocument td(this);
47  td.setDefaultStyleSheet(styleSheet);
48 
49  auto widgetSize = this->size();
50  td.setTextWidth(widgetSize.width()-20.);
51  QPoint origin = QPoint(10, 5);
52 
53  td.setHtml(m_Text);
54 
55  auto textSize = td.size();
56 
57  origin.setX((widgetSize.width() - textSize.width()) / 2.);
58  origin.setY((widgetSize.height() - textSize.height()) / 2.);
59 
60  painter.translate(origin);
61  td.drawContents(&painter);
62 }
void paintEvent(QPaintEvent *event) override
void paintEvent(QPaintEvent *event) override
QmitkSimpleTextOverlayWidget(QWidget *parent=nullptr)