BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
OverlayLabelWidget Class Reference

Description

The OverlayLabelWidget is a semi-transparent overlay label to place on top of other widgets outside of any layout context.

Definition at line 25 of file OverlayLabelWidget.h.

Inheritance diagram for OverlayLabelWidget:
[legend]
Collaboration diagram for OverlayLabelWidget:
[legend]

Public Member Functions

 OverlayLabelWidget (QWidget *parent=nullptr)
 
void setPosition (int x, int y)
 
void setRectangle (const QRect &rect)
 
void setText (const QString &text)
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 

Private Attributes

QRect m_bounding_rect
 
QString m_text
 

Constructor & Destructor Documentation

◆ OverlayLabelWidget()

OverlayLabelWidget::OverlayLabelWidget ( QWidget *  parent = nullptr)

Definition at line 22 of file OverlayLabelWidget.cpp.

23  : QWidget(parent)
24  , m_bounding_rect(QRect(0, 0, 10, 10))
25 {
26  setAttribute(Qt::WA_TransparentForMouseEvents);
27 }

Member Function Documentation

◆ paintEvent()

void OverlayLabelWidget::paintEvent ( QPaintEvent *  event)
overrideprotected

Definition at line 39 of file OverlayLabelWidget.cpp.

40 {
41  Q_UNUSED(event);
42  QPainter painter(this);
43  painter.setBrush(QColor(Qt::lightGray));
44  QFont serifFont("Monospace", DesignerHelper::getSectionFontSize(), QFont::Normal, true);
45  painter.setFont(serifFont);
46  // painter.drawRect(m_bounding_rect);
47  auto margin = GUI::Util::Style::SizeOfLetterM().width();
48  painter.drawText(m_bounding_rect.marginsRemoved(QMargins(margin, margin, margin, margin)),
49  Qt::AlignCenter, m_text);
50 }
static int getSectionFontSize()
Returns system dependent font size.
QSize SizeOfLetterM(const QWidget *widget=nullptr)
Returns size of largest letter of default system font.
Definition: StyleUtils.cpp:113

References DesignerHelper::getSectionFontSize(), m_bounding_rect, m_text, and GUI::Util::Style::SizeOfLetterM().

Here is the call graph for this function:

◆ setPosition()

void OverlayLabelWidget::setPosition ( int  x,
int  y 
)

Definition at line 34 of file OverlayLabelWidget.cpp.

35 {
36  setGeometry(x, y, m_bounding_rect.width(), m_bounding_rect.height());
37 }

References m_bounding_rect.

Referenced by OverlayLabelController::updateLabelGeometry().

◆ setRectangle()

void OverlayLabelWidget::setRectangle ( const QRect &  rect)

Definition at line 29 of file OverlayLabelWidget.cpp.

30 {
31  m_bounding_rect = rect;
32 }

References m_bounding_rect.

Referenced by OverlayLabelController::updateLabelGeometry().

◆ setText()

void OverlayLabelWidget::setText ( const QString &  text)
inline

Definition at line 33 of file OverlayLabelWidget.h.

33 { m_text = text; }

References m_text.

Referenced by OverlayLabelController::setShown().

Member Data Documentation

◆ m_bounding_rect

QRect OverlayLabelWidget::m_bounding_rect
private

Definition at line 40 of file OverlayLabelWidget.h.

Referenced by paintEvent(), setPosition(), and setRectangle().

◆ m_text

QString OverlayLabelWidget::m_text
private

Definition at line 39 of file OverlayLabelWidget.h.

Referenced by paintEvent(), and setText().


The documentation for this class was generated from the following files: