Qt 5.10 Book Examples
chapter20
ElidedText
main.cpp
Go to the documentation of this file.
1
// ======================================================================
2
// main.cpp
3
// ======================================================================
4
// This file is a part of the book
5
// "Qt 5.10 Professional programming with C++"
6
// http://qt-book.com
7
// ======================================================================
8
// Copyright (c) 2017 by Max Schlee
9
// ======================================================================
10
11
#include <QtWidgets>
12
13
// ======================================================================
14
class
ElidedText
:
public
QWidget {
15
protected
:
16
virtual
void
paintEvent
(QPaintEvent*)
17
{
18
QString str =
"This is a long text. Please, resize the window"
;
19
QString strElided =
20
fontMetrics().elidedText(str, Qt::ElideMiddle, width());
21
QPainter painter(
this
);
22
painter.drawText(rect(), strElided);
23
}
24
25
public
:
26
ElidedText
(QWidget* pwgt = 0) : QWidget(pwgt)
27
{
28
}
29
};
30
31
// ----------------------------------------------------------------------
32
int
main
(
int
argc,
char
** argv)
33
{
34
QApplication app(argc, argv);
35
ElidedText
et;
36
et.resize(200, 20);
37
et.show();
38
39
return
app.exec();
40
}
main
int main(int argc, char **argv)
Definition:
main.cpp:15
ElidedText::ElidedText
ElidedText(QWidget *pwgt=0)
Definition:
main.cpp:26
ElidedText
Definition:
main.cpp:14
ElidedText::paintEvent
virtual void paintEvent(QPaintEvent *)
Definition:
main.cpp:16
Generated by
1.8.14