BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
OverlayLabelWidget.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/InfoWidgets/OverlayLabelWidget.cpp
6 //! @brief Implements class OverlayLabelWidget
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
18 #include <QColor>
19 #include <QFont>
20 #include <QPainter>
21 
23  : QWidget(parent), m_bounding_rect(QRect(0, 0, 10, 10))
24 {
25  setAttribute(Qt::WA_TransparentForMouseEvents);
26 }
27 
28 void OverlayLabelWidget::setRectangle(const QRect& rect)
29 {
30  m_bounding_rect = rect;
31 }
32 
34 {
35  setGeometry(x, y, m_bounding_rect.width(), m_bounding_rect.height());
36 }
37 
38 void OverlayLabelWidget::paintEvent(QPaintEvent* event)
39 {
40  Q_UNUSED(event);
41  QPainter painter(this);
42  painter.setBrush(QColor(Qt::lightGray));
43  QFont serifFont("Monospace", DesignerHelper::getSectionFontSize(), QFont::Normal, true);
44  painter.setFont(serifFont);
45  // painter.drawRect(m_bounding_rect);
46  auto margin = StyleUtils::SizeOfLetterM().width();
47  painter.drawText(m_bounding_rect.marginsRemoved(QMargins(margin, margin, margin, margin)),
48  Qt::AlignCenter, m_text);
49 }
Defines class DesignerHelper.
Defines class OverlayLabelWidget.
DefinesStyleUtils namespace.
static int getSectionFontSize()
OverlayLabelWidget(QWidget *parent=0)
void setRectangle(const QRect &rect)
void paintEvent(QPaintEvent *event)
void setPosition(int x, int y)
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:110