Sophie

Sophie

distrib > Mageia > 6 > armv5tl > media > core-updates > by-pkgid > 768f7d9f703884aa2562bf0a651086df > files > 4471

qtbase5-doc-5.9.4-1.1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- charactermap.qdoc -->
  <title>Character Map Example | Qt Widgets 5.9</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.9</td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="examples-widgets.html">Qt Widgets Examples</a></td><td >Character Map Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#characterwidget-class-definition">CharacterWidget Class Definition</a></li>
<li class="level1"><a href="#characterwidget-class-implementation">CharacterWidget Class Implementation</a></li>
<li class="level1"><a href="#mainwindow-class-definition">MainWindow Class Definition</a></li>
<li class="level1"><a href="#mainwindow-class-implementation">MainWindow Class Implementation</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Character Map Example</h1>
<span class="subtitle"></span>
<!-- $$$widgets/charactermap-description -->
<div class="descr"> <a name="details"></a>
<p>The example displays an array of characters which the user can click on to enter text in a line edit. The contents of the line edit can then be copied into the clipboard, and pasted into other applications. The purpose behind this sort of tool is to allow users to enter characters that may be unavailable or difficult to locate on their keyboards.</p>
<div class="border"><p class="centerAlign"><img src="images/charactermap-example.png" alt="" /></p></div><p class="figCaption">Screenshot of the Character Map example</p>
<p>The example consists of the following classes:</p>
<ul>
<li><code>CharacterWidget</code> displays the available characters in the current font and style.</li>
<li><code>MainWindow</code> provides a standard main window that contains font and style information, a view onto the characters, a line edit, and a push button for submitting text to the clipboard.</li>
</ul>
<a name="characterwidget-class-definition"></a>
<h2 id="characterwidget-class-definition">CharacterWidget Class Definition</h2>
<p>The <code>CharacterWidget</code> class is used to display an array of characters in a user-specified font and style. For flexibility, we subclass <a href="qwidget.html">QWidget</a> and reimplement only the functions that we need to provide basic rendering and interaction features.</p>
<p>The class definition looks like this:</p>
<pre class="cpp">

  <span class="keyword">class</span> CharacterWidget : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span>
  {
      Q_OBJECT

  <span class="keyword">public</span>:
      CharacterWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>);
      <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> sizeHint() <span class="keyword">const</span> override;

  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> updateFont(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> <span class="operator">&amp;</span>font);
      <span class="type">void</span> updateSize(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>fontSize);
      <span class="type">void</span> updateStyle(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>fontStyle);
      <span class="type">void</span> updateFontMerging(bool enable);

  <span class="keyword">signals</span>:
      <span class="type">void</span> characterSelected(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>character);

  <span class="keyword">protected</span>:
      <span class="type">void</span> mouseMoveEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) override;
      <span class="type">void</span> mousePressEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) override;
      <span class="type">void</span> paintEvent(<span class="type"><a href="../qtgui/qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span>event) override;

  <span class="keyword">private</span>:
      <span class="type">void</span> calculateSquareSize();

      <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> displayFont;
      <span class="type">int</span> columns;
      <span class="type">int</span> lastKey;
      <span class="type">int</span> squareSize;
  };

</pre>
<p>The widget does not contain any other widgets, so it must provide its own size hint to allow its contents to be displayed correctly. We reimplement <a href="qwidget.html#paintEvent">QWidget::paintEvent</a>() to draw custom content. We also reimplement <a href="qwidget.html#mousePressEvent">QWidget::mousePressEvent</a>() to allow the user to interact with the widget.</p>
<p>The updateFont() and updateStyle() slots are used to update the font and style of the characters in the widget whenever the user changes the settings in the application. The class defines the characterSelected() signal so that other parts of the application are informed whenever the user selects a character in the widget. As a courtesy, the widget provides a tooltip that shows the current character value. We reimplement the <a href="qwidget.html#mouseMoveEvent">QWidget::mouseMoveEvent</a>() event handler and define showToolTip() to enable this feature.</p>
<p>The <code>columns</code>, <code>displayFont</code> and <code>currentKey</code> private data members are used to record the number of columns to be shown, the current font, and the currently highlighted character in the widget.</p>
<a name="characterwidget-class-implementation"></a>
<h2 id="characterwidget-class-implementation">CharacterWidget Class Implementation</h2>
<p>Since the widget is to be used as a simple canvas, the constructor just calls the base class constructor and defines some default values for private data members.</p>
<pre class="cpp">

  CharacterWidget<span class="operator">::</span>CharacterWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
      : <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)<span class="operator">,</span> columns(<span class="number">16</span>)<span class="operator">,</span> lastKey(<span class="operator">-</span><span class="number">1</span>)
  {
      calculateSquareSize();
      setMouseTracking(<span class="keyword">true</span>);
  }

</pre>
<p>We initialize <code>currentKey</code> with a value of -1 to indicate that no character is initially selected. We enable mouse tracking to allow us to follow the movement of the cursor across the widget.</p>
<p>The class provides two functions to allow the font and style to be set up. Each of these modify the widget's display font and call update():</p>
<pre class="cpp">

  <span class="type">void</span> CharacterWidget<span class="operator">::</span>updateFont(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> <span class="operator">&amp;</span>font)
  {
      displayFont<span class="operator">.</span>setFamily(font<span class="operator">.</span>family());
      calculateSquareSize();
      adjustSize();
      update();
  }

  <span class="type">void</span> CharacterWidget<span class="operator">::</span>updateSize(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>fontSize)
  {
      displayFont<span class="operator">.</span>setPointSize(fontSize<span class="operator">.</span>toInt());
      calculateSquareSize();
      adjustSize();
      update();
  }

</pre>
<p>We use a fixed size font for the display. Similarly, a fixed size hint is provided by the sizeHint() function:</p>
<pre class="cpp">

  <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> CharacterWidget<span class="operator">::</span>sizeHint() <span class="keyword">const</span>
  {
      <span class="keyword">return</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span>(columns<span class="operator">*</span>squareSize<span class="operator">,</span> (<span class="number">65536</span><span class="operator">/</span>columns)<span class="operator">*</span>squareSize);
  }

</pre>
<p>Three standard event functions are implemented so that the widget can respond to clicks, provide tooltips, and render the available characters. The paintEvent() shows how the contents of the widget are arranged and displayed:</p>
<pre class="cpp">

  <span class="type">void</span> CharacterWidget<span class="operator">::</span>paintEvent(<span class="type"><a href="../qtgui/qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span>event)
  {
      <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> painter(<span class="keyword">this</span>);
      painter<span class="operator">.</span>fillRect(event<span class="operator">-</span><span class="operator">&gt;</span>rect()<span class="operator">,</span> <span class="type"><a href="../qtgui/qbrush.html">QBrush</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>white));
      painter<span class="operator">.</span>setFont(displayFont);

</pre>
<p>A <a href="../qtgui/qpainter.html">QPainter</a> is created for the widget and, in all cases, we ensure that the widget's background is painted. The painter's font is set to the user-specified display font.</p>
<p>The area of the widget that needs to be redrawn is used to determine which characters need to be displayed:</p>
<pre class="cpp">

      <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> redrawRect <span class="operator">=</span> event<span class="operator">-</span><span class="operator">&gt;</span>rect();
      <span class="type">int</span> beginRow <span class="operator">=</span> redrawRect<span class="operator">.</span>top()<span class="operator">/</span>squareSize;
      <span class="type">int</span> endRow <span class="operator">=</span> redrawRect<span class="operator">.</span>bottom()<span class="operator">/</span>squareSize;
      <span class="type">int</span> beginColumn <span class="operator">=</span> redrawRect<span class="operator">.</span>left()<span class="operator">/</span>squareSize;
      <span class="type">int</span> endColumn <span class="operator">=</span> redrawRect<span class="operator">.</span>right()<span class="operator">/</span>squareSize;

</pre>
<p>Using integer division, we obtain the row and column numbers of each characters that should be displayed, and we draw a square on the widget for each character displayed.</p>
<pre class="cpp">

      painter<span class="operator">.</span>setPen(<span class="type"><a href="../qtgui/qpen.html">QPen</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>gray));
      <span class="keyword">for</span> (<span class="type">int</span> row <span class="operator">=</span> beginRow; row <span class="operator">&lt;</span><span class="operator">=</span> endRow; <span class="operator">+</span><span class="operator">+</span>row) {
          <span class="keyword">for</span> (<span class="type">int</span> column <span class="operator">=</span> beginColumn; column <span class="operator">&lt;</span><span class="operator">=</span> endColumn; <span class="operator">+</span><span class="operator">+</span>column) {
              painter<span class="operator">.</span>drawRect(column<span class="operator">*</span>squareSize<span class="operator">,</span> row<span class="operator">*</span>squareSize<span class="operator">,</span> squareSize<span class="operator">,</span> squareSize);
          }
      }

</pre>
<p>The symbols for each character in the array are drawn within each square, with the symbol for the most recently selected character displayed in red:</p>
<pre class="cpp">

      <span class="type"><a href="../qtgui/qfontmetrics.html">QFontMetrics</a></span> fontMetrics(displayFont);
      painter<span class="operator">.</span>setPen(<span class="type"><a href="../qtgui/qpen.html">QPen</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>black));
      <span class="keyword">for</span> (<span class="type">int</span> row <span class="operator">=</span> beginRow; row <span class="operator">&lt;</span><span class="operator">=</span> endRow; <span class="operator">+</span><span class="operator">+</span>row) {

          <span class="keyword">for</span> (<span class="type">int</span> column <span class="operator">=</span> beginColumn; column <span class="operator">&lt;</span><span class="operator">=</span> endColumn; <span class="operator">+</span><span class="operator">+</span>column) {

              <span class="type">int</span> key <span class="operator">=</span> row<span class="operator">*</span>columns <span class="operator">+</span> column;
              painter<span class="operator">.</span>setClipRect(column<span class="operator">*</span>squareSize<span class="operator">,</span> row<span class="operator">*</span>squareSize<span class="operator">,</span> squareSize<span class="operator">,</span> squareSize);

              <span class="keyword">if</span> (key <span class="operator">=</span><span class="operator">=</span> lastKey)
                  painter<span class="operator">.</span>fillRect(column<span class="operator">*</span>squareSize <span class="operator">+</span> <span class="number">1</span><span class="operator">,</span> row<span class="operator">*</span>squareSize <span class="operator">+</span> <span class="number">1</span><span class="operator">,</span> squareSize<span class="operator">,</span> squareSize<span class="operator">,</span> <span class="type"><a href="../qtgui/qbrush.html">QBrush</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>red));

              painter<span class="operator">.</span>drawText(column<span class="operator">*</span>squareSize <span class="operator">+</span> (squareSize <span class="operator">/</span> <span class="number">2</span>) <span class="operator">-</span> fontMetrics<span class="operator">.</span>width(<span class="type"><a href="../qtcore/qchar.html">QChar</a></span>(key))<span class="operator">/</span><span class="number">2</span><span class="operator">,</span>
                               row<span class="operator">*</span>squareSize <span class="operator">+</span> <span class="number">4</span> <span class="operator">+</span> fontMetrics<span class="operator">.</span>ascent()<span class="operator">,</span>
                               <span class="type"><a href="../qtcore/qstring.html">QString</a></span>(<span class="type"><a href="../qtcore/qchar.html">QChar</a></span>(key)));
          }
      }
  }

</pre>
<p>We do not need to take into account the difference between the area displayed in the viewport and the area we are drawing on because everything outside the visible area will be clipped.</p>
<p>The mousePressEvent() defines how the widget responds to mouse clicks.</p>
<pre class="cpp">

  <span class="type">void</span> CharacterWidget<span class="operator">::</span>mousePressEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event)
  {
      <span class="keyword">if</span> (event<span class="operator">-</span><span class="operator">&gt;</span>button() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>LeftButton) {
          lastKey <span class="operator">=</span> (event<span class="operator">-</span><span class="operator">&gt;</span>y()<span class="operator">/</span>squareSize)<span class="operator">*</span>columns <span class="operator">+</span> event<span class="operator">-</span><span class="operator">&gt;</span>x()<span class="operator">/</span>squareSize;
          <span class="keyword">if</span> (<span class="type"><a href="../qtcore/qchar.html">QChar</a></span>(lastKey)<span class="operator">.</span>category() <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qchar.html">QChar</a></span><span class="operator">::</span>Other_NotAssigned)
              <span class="keyword">emit</span> characterSelected(<span class="type"><a href="../qtcore/qstring.html">QString</a></span>(<span class="type"><a href="../qtcore/qchar.html">QChar</a></span>(lastKey)));
          update();
      }
      <span class="keyword">else</span>
          <span class="type"><a href="qwidget.html">QWidget</a></span><span class="operator">::</span>mousePressEvent(event);
  }

</pre>
<p>We are only interested when the user clicks with the left mouse button over the widget. When this happens, we calculate which character was selected and emit the characterSelected() signal. The character's number is found by dividing the x and y-coordinates of the click by the size of each character's grid square. Since the number of columns in the widget is defined by the <code>columns</code> variable, we simply multiply the row index by that value and add the column number to obtain the character number.</p>
<p>If any other mouse button is pressed, the event is passed on to the <a href="qwidget.html">QWidget</a> base class. This ensures that the event can be handled properly by any other interested widgets.</p>
<p>The mouseMoveEvent() maps the mouse cursor's position in global coordinates to widget coordinates, and determines the character that was clicked by performing the calculation</p>
<pre class="cpp">

  <span class="type">void</span> CharacterWidget<span class="operator">::</span>mouseMoveEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event)
  {
      <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span> widgetPosition <span class="operator">=</span> mapFromGlobal(event<span class="operator">-</span><span class="operator">&gt;</span>globalPos());
      <span class="type"><a href="../qtcore/qtglobal.html#uint-typedef">uint</a></span> key <span class="operator">=</span> (widgetPosition<span class="operator">.</span>y()<span class="operator">/</span>squareSize)<span class="operator">*</span>columns <span class="operator">+</span> widgetPosition<span class="operator">.</span>x()<span class="operator">/</span>squareSize;

      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text <span class="operator">=</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span><span class="operator">::</span>fromLatin1(<span class="string">&quot;&lt;p&gt;Character: &lt;span style=\&quot;font-size: 24pt; font-family: %1\&quot;&gt;&quot;</span>)<span class="operator">.</span>arg(displayFont<span class="operator">.</span>family())
                    <span class="operator">+</span> <span class="type"><a href="../qtcore/qchar.html">QChar</a></span>(key)
                    <span class="operator">+</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span><span class="operator">::</span>fromLatin1(<span class="string">&quot;&lt;/span&gt;&lt;p&gt;Value: 0x&quot;</span>)
                    <span class="operator">+</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span><span class="operator">::</span>number(key<span class="operator">,</span> <span class="number">16</span>);
      <span class="type"><a href="qtooltip.html">QToolTip</a></span><span class="operator">::</span>showText(event<span class="operator">-</span><span class="operator">&gt;</span>globalPos()<span class="operator">,</span> text<span class="operator">,</span> <span class="keyword">this</span>);
  }

</pre>
<p>The tooltip is given a position defined in global coordinates.</p>
<a name="mainwindow-class-definition"></a>
<h2 id="mainwindow-class-definition">MainWindow Class Definition</h2>
<p>The <code>MainWindow</code> class provides a minimal user interface for the example, with only a constructor, slots that respond to signals emitted by standard widgets, and some convenience functions that are used to set up the user interface.</p>
<p>The class definition looks like this:</p>
<pre class="cpp">

  <span class="keyword">class</span> MainWindow : <span class="keyword">public</span> <span class="type"><a href="qmainwindow.html">QMainWindow</a></span>
  {
      Q_OBJECT

  <span class="keyword">public</span>:
      MainWindow();

  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> filterChanged(<span class="type">int</span>);
      <span class="type">void</span> findStyles(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> <span class="operator">&amp;</span>font);
      <span class="type">void</span> findSizes(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> <span class="operator">&amp;</span>font);
      <span class="type">void</span> insertCharacter(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>character);
  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      <span class="type">void</span> updateClipboard();
  <span class="preprocessor">#endif</span>
      <span class="type">void</span> showInfo();

  <span class="keyword">private</span>:
      CharacterWidget <span class="operator">*</span>characterWidget;
      <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>filterCombo;
      <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>styleCombo;
      <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>sizeCombo;
      <span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span> <span class="operator">*</span>fontCombo;
      <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>lineEdit;
      <span class="type"><a href="qscrollarea.html">QScrollArea</a></span> <span class="operator">*</span>scrollArea;
      <span class="type"><a href="qcheckbox.html">QCheckBox</a></span> <span class="operator">*</span>fontMerging;
  };

</pre>
<p>The main window contains various widgets that are used to control how the characters will be displayed, and defines the findFonts() function for clarity and convenience. The findStyles() slot is used by the widgets to determine the styles that are available, insertCharacter() inserts a user-selected character into the window's line edit, and updateClipboard() synchronizes the clipboard with the contents of the line edit.</p>
<a name="mainwindow-class-implementation"></a>
<h2 id="mainwindow-class-implementation">MainWindow Class Implementation</h2>
<p>In the constructor, we set up the window's central widget and fill it with some standard widgets (two comboboxes, a line edit, and a push button). We also construct a CharacterWidget custom widget, and add a <a href="qscrollarea.html">QScrollArea</a> so that we can view its contents:</p>
<pre class="cpp">

  Q_DECLARE_METATYPE(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>FontFilter)

  MainWindow<span class="operator">::</span>MainWindow()
  {
      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>fileMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;File&quot;</span>));
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;Quit&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qwidget.html">QWidget</a></span><span class="operator">::</span>close);
      <span class="type"><a href="qmenu.html">QMenu</a></span> <span class="operator">*</span>helpMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;&amp;Help&quot;</span>));
      helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;Show Font Info&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>showInfo);
      helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(tr(<span class="string">&quot;About &amp;Qt&quot;</span>)<span class="operator">,</span> qApp<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>aboutQt);

      <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>centralWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>filterLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Filter:&quot;</span>));
      filterCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;All&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>AllFonts));
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Scalable&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>ScalableFonts));
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Monospaced&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>MonospacedFonts));
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Proportional&quot;</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span><span class="operator">::</span>fromValue(<span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>ProportionalFonts));
      filterCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(<span class="number">0</span>);
      connect(filterCombo<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qcombobox.html">QComboBox</a></span><span class="operator">::</span>currentIndexChanged)<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>filterChanged);

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>fontLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Font:&quot;</span>));
      fontCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span>;
      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>sizeLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Size:&quot;</span>));
      sizeCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>styleLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Style:&quot;</span>));
      styleCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>fontMergingLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Automatic Font Merging:&quot;</span>));
      fontMerging <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcheckbox.html">QCheckBox</a></span>;
      fontMerging<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="keyword">true</span>);

      scrollArea <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qscrollarea.html">QScrollArea</a></span>;
      characterWidget <span class="operator">=</span> <span class="keyword">new</span> CharacterWidget;
      scrollArea<span class="operator">-</span><span class="operator">&gt;</span>setWidget(characterWidget);

</pre>
<p><a href="qscrollarea.html">QScrollArea</a> provides a viewport onto the <code>CharacterWidget</code> when we set its widget and handles much of the work needed to provide a scrolling viewport.</p>
<p>The font combo box is automatically popuplated with a list of available fonts. We list the available styles for the current font in the style combobox using the following function:</p>
<pre class="cpp">

      findStyles(fontCombo<span class="operator">-</span><span class="operator">&gt;</span>currentFont());

</pre>
<p>The line edit and push button are used to supply text to the clipboard:</p>
<pre class="cpp">

      lineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>;
      lineEdit<span class="operator">-</span><span class="operator">&gt;</span>setClearButtonEnabled(<span class="keyword">true</span>);
  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>clipboardButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">&quot;&amp;To clipboard&quot;</span>));

</pre>
<p>We also obtain a clipboard object so that we can send text entered by the user to other applications.</p>
<p>Most of the signals emitted in the example come from standard widgets. We connect these signals to slots in this class, and to the slots provided by other widgets.</p>
<pre class="cpp">

      connect(fontCombo<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>currentFontChanged<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>findStyles);
      connect(fontCombo<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>currentFontChanged<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>findSizes);
      connect(fontCombo<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qfontcombobox.html">QFontComboBox</a></span><span class="operator">::</span>currentFontChanged<span class="operator">,</span>
              characterWidget<span class="operator">,</span> <span class="operator">&amp;</span>CharacterWidget<span class="operator">::</span>updateFont);
      connect(sizeCombo<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span><span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qcombobox.html">QComboBox</a></span><span class="operator">::</span>currentIndexChanged)<span class="operator">,</span>
              characterWidget<span class="operator">,</span> <span class="operator">&amp;</span>CharacterWidget<span class="operator">::</span>updateSize);
      connect(styleCombo<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span><span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qcombobox.html">QComboBox</a></span><span class="operator">::</span>currentIndexChanged)<span class="operator">,</span>
              characterWidget<span class="operator">,</span> <span class="operator">&amp;</span>CharacterWidget<span class="operator">::</span>updateStyle);

</pre>
<p>The font combobox's <a href="qfontcombobox.html#currentFontChanged">currentFontChanged()</a> signal is connected to the findStyles() function so that the list of available styles can be shown for each font that is used. Since both the font and the style can be changed by the user, the font combobox's currentFontChanged() signal and the style combobox's <a href="qcombobox.html#currentIndexChanged">currentIndexChanged()</a> are connected directly to the character widget.</p>
<p>The final two connections allow characters to be selected in the character widget, and text to be inserted into the clipboard:</p>
<pre class="cpp">

      connect(characterWidget<span class="operator">,</span> <span class="operator">&amp;</span>CharacterWidget<span class="operator">::</span>characterSelected<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>insertCharacter);

  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      connect(clipboardButton<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span>MainWindow<span class="operator">::</span>updateClipboard);
  <span class="preprocessor">#endif</span>

</pre>
<p>The character widget emits the characterSelected() custom signal when the user clicks on a character, and this is handled by the insertCharacter() function in this class. The clipboard is changed when the push button emits the clicked() signal, and we handle this with the updateClipboard() function.</p>
<p>The remaining code in the constructor sets up the layout of the central widget, and provides a window title:</p>
<pre class="cpp">

      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>controlsLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>;
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(filterLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(filterCombo<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontCombo<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(sizeLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(sizeCombo<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(styleLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(styleCombo<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontMergingLabel);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(fontMerging<span class="operator">,</span> <span class="number">1</span>);
      controlsLayout<span class="operator">-</span><span class="operator">&gt;</span>addStretch(<span class="number">1</span>);

      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>lineLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>;
      lineLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(lineEdit<span class="operator">,</span> <span class="number">1</span>);
      lineLayout<span class="operator">-</span><span class="operator">&gt;</span>addSpacing(<span class="number">12</span>);
  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
      lineLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(clipboardButton);
  <span class="preprocessor">#endif</span>

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>centralLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;
      centralLayout<span class="operator">-</span><span class="operator">&gt;</span>addLayout(controlsLayout);
      centralLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(scrollArea<span class="operator">,</span> <span class="number">1</span>);
      centralLayout<span class="operator">-</span><span class="operator">&gt;</span>addSpacing(<span class="number">4</span>);
      centralLayout<span class="operator">-</span><span class="operator">&gt;</span>addLayout(lineLayout);
      centralWidget<span class="operator">-</span><span class="operator">&gt;</span>setLayout(centralLayout);

      setCentralWidget(centralWidget);
      setWindowTitle(tr(<span class="string">&quot;Character Map&quot;</span>));
  }

</pre>
<p>The font combobox is automatically populated with a list of available font families. The styles that can be used with each font are found by the findStyles() function. This function is called whenever the user selects a different font in the font combobox.</p>
<pre class="cpp">

  <span class="type">void</span> MainWindow<span class="operator">::</span>findStyles(<span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> <span class="operator">&amp;</span>font)
  {
      <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span> fontDatabase;
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> currentItem <span class="operator">=</span> styleCombo<span class="operator">-</span><span class="operator">&gt;</span>currentText();
      styleCombo<span class="operator">-</span><span class="operator">&gt;</span>clear();

</pre>
<p>We begin by recording the currently selected style, and we clear the style combobox so that we can insert the styles associated with the current font family.</p>
<pre class="cpp">

      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> style;
      foreach (style<span class="operator">,</span> fontDatabase<span class="operator">.</span>styles(font<span class="operator">.</span>family()))
          styleCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(style);

      <span class="type">int</span> styleIndex <span class="operator">=</span> styleCombo<span class="operator">-</span><span class="operator">&gt;</span>findText(currentItem);

      <span class="keyword">if</span> (styleIndex <span class="operator">=</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>)
          styleCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(<span class="number">0</span>);
      <span class="keyword">else</span>
          styleCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(styleIndex);
  }

</pre>
<p>We use the font database to collect the styles that are available for the current font, and insert them into the style combobox. The current item is reset if the original style is not available for this font.</p>
<p>The last two functions are slots that respond to signals from the character widget and the main window's push button. The insertCharacter() function is used to insert characters from the character widget when the user clicks a character:</p>
<pre class="cpp">

  <span class="type">void</span> MainWindow<span class="operator">::</span>insertCharacter(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>character)
  {
      lineEdit<span class="operator">-</span><span class="operator">&gt;</span>insert(character);
  }

</pre>
<p>The character is inserted into the line edit at the current cursor position.</p>
<p>The main window's &quot;To clipboard&quot; push button is connected to the updateClipboard() function so that, when it is clicked, the clipboard is updated to contain the contents of the line edit:</p>
<pre class="cpp">

  <span class="preprocessor">#ifndef QT_NO_CLIPBOARD</span>
  <span class="type">void</span> MainWindow<span class="operator">::</span>updateClipboard()
  {
      <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>clipboard()<span class="operator">-</span><span class="operator">&gt;</span>setText(lineEdit<span class="operator">-</span><span class="operator">&gt;</span>text()<span class="operator">,</span> <span class="type"><a href="../qtgui/qclipboard.html">QClipboard</a></span><span class="operator">::</span>Clipboard);
      <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>clipboard()<span class="operator">-</span><span class="operator">&gt;</span>setText(lineEdit<span class="operator">-</span><span class="operator">&gt;</span>text()<span class="operator">,</span> <span class="type"><a href="../qtgui/qclipboard.html">QClipboard</a></span><span class="operator">::</span>Selection);
  }
  <span class="preprocessor">#endif</span>

  <span class="keyword">class</span> FontInfoDialog : <span class="keyword">public</span> <span class="type"><a href="qdialog.html">QDialog</a></span>
  {
  <span class="keyword">public</span>:
      <span class="keyword">explicit</span> FontInfoDialog(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> Q_NULLPTR);

  <span class="keyword">private</span>:
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text() <span class="keyword">const</span>;
  };

  FontInfoDialog<span class="operator">::</span>FontInfoDialog(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent) : <span class="type"><a href="qdialog.html">QDialog</a></span>(parent)
  {
      setWindowFlags(windowFlags() <span class="operator">&amp;</span> <span class="operator">~</span><span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>WindowContextHelpButtonHint);
      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>mainLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(<span class="keyword">this</span>);
      <span class="type"><a href="qplaintextedit.html">QPlainTextEdit</a></span> <span class="operator">*</span>textEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qplaintextedit.html">QPlainTextEdit</a></span>(text()<span class="operator">,</span> <span class="keyword">this</span>);
      textEdit<span class="operator">-</span><span class="operator">&gt;</span>setReadOnly(<span class="keyword">true</span>);
      textEdit<span class="operator">-</span><span class="operator">&gt;</span>setFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>FixedFont));
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(textEdit);
      <span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span> <span class="operator">*</span>buttonBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span>(<span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span><span class="operator">::</span>Close<span class="operator">,</span> <span class="keyword">this</span>);
      connect(buttonBox<span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qdialogbuttonbox.html">QDialogButtonBox</a></span><span class="operator">::</span>rejected<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&amp;</span><span class="type"><a href="qdialog.html">QDialog</a></span><span class="operator">::</span>reject);
      mainLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(buttonBox);
  }

  <span class="type"><a href="../qtcore/qstring.html">QString</a></span> FontInfoDialog<span class="operator">::</span>text() <span class="keyword">const</span>
  {
      <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text;
      <span class="type"><a href="../qtcore/qtextstream.html">QTextStream</a></span> str(<span class="operator">&amp;</span>text);
      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> defaultFont <span class="operator">=</span> <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>GeneralFont);
      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> fixedFont <span class="operator">=</span> <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>FixedFont);
      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> titleFont <span class="operator">=</span> <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>TitleFont);
      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> smallestReadableFont <span class="operator">=</span> <span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>systemFont(<span class="type"><a href="../qtgui/qfontdatabase.html">QFontDatabase</a></span><span class="operator">::</span>SmallestReadableFont);

      str <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Qt &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> QT_VERSION_STR <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot; on &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>platformName()
          <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> logicalDpiX() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;DPI&quot;</span>;
      <span class="keyword">if</span> (<span class="operator">!</span><a href="../qtcore/qtglobal.html#qFuzzyCompare">qFuzzyCompare</a>(devicePixelRatioF()<span class="operator">,</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">1</span>)))
          str  <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, device pixel ratio: &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> devicePixelRatioF();
      str <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;\n\nDefault font : &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> defaultFont<span class="operator">.</span>family() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> defaultFont<span class="operator">.</span>pointSizeF() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;pt\n&quot;</span>
          <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Fixed font   : &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> fixedFont<span class="operator">.</span>family() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> fixedFont<span class="operator">.</span>pointSizeF() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;pt\n&quot;</span>
          <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Title font   : &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> titleFont<span class="operator">.</span>family() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> titleFont<span class="operator">.</span>pointSizeF() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;pt\n&quot;</span>
          <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Smallest font: &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> smallestReadableFont<span class="operator">.</span>family() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;, &quot;</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> smallestReadableFont<span class="operator">.</span>pointSizeF() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;pt\n&quot;</span>;

      <span class="keyword">return</span> text;
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>showInfo()
  {
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> screenGeometry <span class="operator">=</span> <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>desktop()<span class="operator">-</span><span class="operator">&gt;</span>screenGeometry(<span class="keyword">this</span>);
      FontInfoDialog <span class="operator">*</span>dialog <span class="operator">=</span> <span class="keyword">new</span> FontInfoDialog(<span class="keyword">this</span>);
      dialog<span class="operator">-</span><span class="operator">&gt;</span>setWindowTitle(tr(<span class="string">&quot;Fonts&quot;</span>));
      dialog<span class="operator">-</span><span class="operator">&gt;</span>setAttribute(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>WA_DeleteOnClose);
      dialog<span class="operator">-</span><span class="operator">&gt;</span>resize(screenGeometry<span class="operator">.</span>width() <span class="operator">/</span> <span class="number">4</span><span class="operator">,</span> screenGeometry<span class="operator">.</span>height() <span class="operator">/</span> <span class="number">4</span>);
      dialog<span class="operator">-</span><span class="operator">&gt;</span>show();
  }

</pre>
<p>We copy all the text from the line edit to the clipboard, but we do not clear the line edit.</p>
<p>Files:</p>
<ul>
<li><a href="qtwidgets-widgets-charactermap-characterwidget-cpp.html">widgets/charactermap/characterwidget.cpp</a></li>
<li><a href="qtwidgets-widgets-charactermap-characterwidget-h.html">widgets/charactermap/characterwidget.h</a></li>
<li><a href="qtwidgets-widgets-charactermap-mainwindow-cpp.html">widgets/charactermap/mainwindow.cpp</a></li>
<li><a href="qtwidgets-widgets-charactermap-mainwindow-h.html">widgets/charactermap/mainwindow.h</a></li>
<li><a href="qtwidgets-widgets-charactermap-main-cpp.html">widgets/charactermap/main.cpp</a></li>
<li><a href="qtwidgets-widgets-charactermap-charactermap-pro.html">widgets/charactermap/charactermap.pro</a></li>
</ul>
</div>
<!-- @@@widgets/charactermap -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>