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

Description

The StatusLabel class shows a single line of text on a white background. Opposite to QLabel, if text string is too long for current size, it will be clipped.

This class is intended for ColorMapLabel, where the size of font is adjusted automatically depending from available space.

Definition at line 28 of file StatusLabel.h.

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

Public Member Functions

 StatusLabel (QWidget *parent=nullptr)
 
void setAlignment (Qt::Alignment)
 
void setFont (const QFont &font)
 
void setPointSize (int pointSize)
 
void setText (const QString &text)
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 

Private Attributes

Qt::Alignment m_alignment
 
QFont m_font
 
QString m_text
 

Constructor & Destructor Documentation

◆ StatusLabel()

StatusLabel::StatusLabel ( QWidget *  parent = nullptr)
explicit

Definition at line 34 of file StatusLabel.cpp.

35  : QFrame(parent)
36  , m_font("Monospace", default_text_size(), QFont::Normal, false)
37 {
38  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
39  setFixedHeight(default_label_height());
40 }
QFont m_font
Definition: StatusLabel.h:45

Member Function Documentation

◆ paintEvent()

void StatusLabel::paintEvent ( QPaintEvent *  event)
overrideprotected

Definition at line 66 of file StatusLabel.cpp.

67 {
68  QWidget::paintEvent(event);
69 
70  QPainter painter(this);
71  painter.setBrush(QColor(Qt::black));
72  painter.setPen(QColor(Qt::black));
73  painter.setFont(m_font);
74 
75  QRect textRect(0, 0, geometry().width(), geometry().height());
76  painter.fillRect(textRect, QColor(Qt::white));
77  painter.drawText(textRect, m_alignment, m_text);
78 }
QString m_text
Definition: StatusLabel.h:43
Qt::Alignment m_alignment
Definition: StatusLabel.h:44

References m_alignment, m_font, and m_text.

◆ setAlignment()

void StatusLabel::setAlignment ( Qt::Alignment  alignment)

Definition at line 60 of file StatusLabel.cpp.

61 {
62  m_alignment = alignment;
63  update();
64 }

References m_alignment.

◆ setFont()

void StatusLabel::setFont ( const QFont &  font)

Definition at line 48 of file StatusLabel.cpp.

49 {
50  m_font = font;
51  update();
52 }

References m_font.

◆ setPointSize()

void StatusLabel::setPointSize ( int  pointSize)

Definition at line 54 of file StatusLabel.cpp.

55 {
56  m_font.setPointSize(pointSize);
57  update();
58 }

References m_font.

◆ setText()

void StatusLabel::setText ( const QString &  text)

Definition at line 42 of file StatusLabel.cpp.

43 {
44  m_text = text;
45  update();
46 }

References m_text.

Referenced by PlotStatusLabel::onPlotStatusString(), Plot1DCanvas::onStatusString(), SpecularPlotCanvas::onStatusString(), and ColorMapCanvas::onStatusString().

Member Data Documentation

◆ m_alignment

Qt::Alignment StatusLabel::m_alignment
private

Definition at line 44 of file StatusLabel.h.

Referenced by paintEvent(), and setAlignment().

◆ m_font

QFont StatusLabel::m_font
private

Definition at line 45 of file StatusLabel.h.

Referenced by paintEvent(), setFont(), and setPointSize().

◆ m_text

QString StatusLabel::m_text
private

Definition at line 43 of file StatusLabel.h.

Referenced by paintEvent(), and setText().


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