⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qfd-qfd-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - qfd/qfd.cpp example file</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b>  <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align=center>Font Displayer</h1><br clear="all">  This example program displays all characters of a font.  <hr>  Header file: <pre>/****************************************************************************** &#36;Id&#58; qt/examples/qfd/fontdisplayer.h   2.3.8   edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of an example program for Qt.  This example** program may be used, distributed and modified without limitation.*******************************************************************************/#ifndef FontDisplayer_H#define FontDisplayer_H#include &lt;<a href="qframe-h.html">qframe.h</a>&gt;#include &lt;<a href="qmainwindow-h.html">qmainwindow.h</a>&gt;class QSlider;class FontRowTable : public QFrame {    Q_OBJECTpublic:    FontRowTable( <a href="qwidget.html">QWidget</a>* parent=0, const char* name=0 );    <a href="qsize.html">QSize</a> sizeHint() const;signals:    void fontInformation(const QString&amp;);public slots:    void setRow(int);protected:    <a href="qsize.html">QSize</a> cellSize() const;    void paintEvent( <a href="qpaintevent.html">QPaintEvent</a>* );private:    int row;};class FontDisplayer : public QMainWindow {    Q_OBJECTpublic:    FontDisplayer( <a href="qwidget.html">QWidget</a>* parent=0, const char* name=0 );};#endif</pre>  <hr>  Implementation: <pre>/****************************************************************************** &#36;Id&#58; qt/examples/qfd/fontdisplayer.cpp   2.3.8   edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of an example program for Qt.  This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "fontdisplayer.h"#include &lt;<a href="qslider-h.html">qslider.h</a>&gt;#include &lt;<a href="qspinbox-h.html">qspinbox.h</a>&gt;#include &lt;<a href="qpainter-h.html">qpainter.h</a>&gt;#include &lt;<a href="qtoolbar-h.html">qtoolbar.h</a>&gt;#include &lt;<a href="qstatusbar-h.html">qstatusbar.h</a>&gt;#include &lt;stdlib.h&gt;FontRowTable::FontRowTable( <a href="qwidget.html">QWidget</a>* parent, const char* name ) :    <a href="qframe.html">QFrame</a>(parent,name){    <a href="qwidget.html#e84bbe">setBackgroundMode</a>(PaletteBase);    <a href="qframe.html#558f79">setFrameStyle</a>(Panel|Sunken);    <a href="qframe.html#b11d00">setMargin</a>(8);    <a href=#236>setRow</a>(0);}<a href="qsize.html">QSize</a> <a name="233"></a>FontRowTable::sizeHint() const{    return 16*cellSize()+QSize(2,2)*(<a href="qframe.html#cb5472">margin</a>()+frameWidth());}<a href="qsize.html">QSize</a> <a name="234"></a>FontRowTable::cellSize() const{    <a href="qfontmetrics.html">QFontMetrics</a> fm = fontMetrics();    return QSize( fm.<a href="qfontmetrics.html#20f575">maxWidth</a>(), fm.<a href="qfontmetrics.html#e6e380">lineSpacing</a>()+1 );}void <a name="235"></a>FontRowTable::paintEvent( <a href="qpaintevent.html">QPaintEvent</a>* e ){    <a href="qframe.html#963e1a">QFrame::paintEvent</a>(e);    <a href="qpainter.html">QPainter</a> p(this);    p.<a href="qpainter.html#15cc78">setClipRegion</a>(e-&gt;<a href="qpaintevent.html#dc5fc5">region</a>());    <a href="qrect.html">QRect</a> r = e-&gt;<a href="qpaintevent.html#2d6e18">rect</a>();    <a href="qfontmetrics.html">QFontMetrics</a> fm = fontMetrics();    int ml = frameWidth()+margin() + 1 + QMAX(0,-fm.<a href="qfontmetrics.html#de5799">minLeftBearing</a>());    int mt = frameWidth()+margin();    <a href="qsize.html">QSize</a> cell((<a href="qwidget.html#2edab1">width</a>()-15-ml)/16,(<a href="qwidget.html#e3c588">height</a>()-15-mt)/16);    if ( !cell.<a href="qsize.html#37cddf">width</a>() || !cell.<a href="qsize.html#a35c26">height</a>() )        return;    int mini = r.<a href="qrect.html#369cab">left</a>() / cell.<a href="qsize.html#37cddf">width</a>();    int maxi = (r.<a href="qrect.html#896e32">right</a>()+cell.<a href="qsize.html#37cddf">width</a>()-1) / cell.<a href="qsize.html#37cddf">width</a>();    int minj = r.<a href="qrect.html#4dd27e">top</a>() / cell.<a href="qsize.html#a35c26">height</a>();    int maxj = (r.<a href="qrect.html#2de4b0">bottom</a>()+cell.<a href="qsize.html#a35c26">height</a>()-1) / cell.<a href="qsize.html#a35c26">height</a>();    int h = fm.<a href="qfontmetrics.html#341253">height</a>();    <a href="qcolor.html">QColor</a> body(255,255,192);    <a href="qcolor.html">QColor</a> negative(255,192,192);    <a href="qcolor.html">QColor</a> positive(192,192,255);    <a href="qcolor.html">QColor</a> rnegative(255,128,128);    <a href="qcolor.html">QColor</a> rpositive(128,128,255);    for (int j = minj; j&lt;=maxj; j++) {        for (int i = mini; i&lt;=maxi; i++) {            if ( i &lt; 16 &amp;&amp; j &lt; 16 ) {                int x = i*cell.<a href="qsize.html#37cddf">width</a>();                int y = j*cell.<a href="qsize.html#a35c26">height</a>();                <a href="qchar.html">QChar</a> ch = QChar(j*16+i,row);                if ( fm.<a href="qfontmetrics.html#245094">inFont</a>(ch) ) {                    int w = fm.<a href="qfontmetrics.html#3b6f39">width</a>(ch);                    int l = fm.<a href="qfontmetrics.html#54cc7d">leftBearing</a>(ch);                    int r = fm.<a href="qfontmetrics.html#1057f3">rightBearing</a>(ch);                    x += ml;                    y += mt+h;                    p.<a href="qpainter.html#5308a7">fillRect</a>(x,y,w,-h,body);                    if ( w ) {                        if ( l ) {                            p.<a href="qpainter.html#5308a7">fillRect</a>(x+(l&gt;0?0:l), y-h/2, abs(l),-h/2,                                       l &lt; 0 ? negative : positive);                        }                        if ( r ) {                            p.<a href="qpainter.html#5308a7">fillRect</a>(x+w-(r&gt;0?r:0),y+2, abs(r),-h/2,                                       r &lt; 0 ? rnegative : rpositive);                        }                    }                    <a href="qstring.html">QString</a> s;                    s += ch;                    p.<a href="qpainter.html#0183e4">setPen</a>(<a href="qpen.html">QPen</a>(Qt::black));                    p.<a href="qpainter.html#0f088f">drawText</a>(x,y,s);                }            }        }    }}void <a name="236"></a>FontRowTable::setRow(int r){    row = r;    <a href="qfontmetrics.html">QFontMetrics</a> fm = fontMetrics();    <a href="qstring.html">QString</a> str;    str.<a href="qstring.html#926f67">sprintf</a>("mLB=%d mRB=%d mW=%d",        fm.<a href="qfontmetrics.html#de5799">minLeftBearing</a>(),        fm.<a href="qfontmetrics.html#108c37">minRightBearing</a>(),        fm.<a href="qfontmetrics.html#20f575">maxWidth</a>()        );    emit fontInformation(str);    <a href="qwidget.html#f3f721">update</a>();}FontDisplayer::FontDisplayer( <a href="qwidget.html">QWidget</a>* parent, const char* name ) :    <a href="qmainwindow.html">QMainWindow</a>(parent,name){    FontRowTable* table = new FontRowTable(this);    <a href="qtoolbar.html">QToolBar</a>* controls = new <a href="qtoolbar.html">QToolBar</a>(this);    <a href="qspinbox.html">QSpinBox</a> *row = new <a href="qspinbox.html">QSpinBox</a>(0,255,1,controls);    <a href="qobject.html#fbde73">connect</a>(row,SIGNAL(valueChanged(int)),table,SLOT(setRow(int)));    <a href="qobject.html#fbde73">connect</a>(table,SIGNAL(fontInformation(const QString&amp;)),        <a href="qmainwindow.html#530937">statusBar</a>(),SLOT(message(const QString&amp;)));    table-&gt;setRow(0);    <a href="qmainwindow.html#fce9ba">setCentralWidget</a>(table);}</pre>  <hr>  Main:<pre>/****************************************************************************** &#36;Id&#58; qt/examples/qfd/qfd.cpp   2.3.8   edited 2004-05-12 $**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of an example program for Qt.  This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "fontdisplayer.h"#include &lt;<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>&gt;#include &lt;<a name="qslider.h"></a><a href="qslider-h.html">qslider.h</a>&gt;#include &lt;<a name="qpainter.h"></a><a href="qpainter-h.html">qpainter.h</a>&gt;#include &lt;<a name="qstatusbar.h"></a><a href="qstatusbar-h.html">qstatusbar.h</a>&gt;int main(int argc, char** argv){    // Use an interesting font    <a name="QApplication::setFont"></a><a href="qapplication.html#3d926a">QApplication::setFont</a>(<a name="QFont"></a><a href="qfont.html">QFont</a>("unifont",16));    <a name="QApplication"></a><a href="qapplication.html">QApplication</a> app(argc,argv);    FontDisplayer m;    <a name="QSize"></a><a href="qsize.html">QSize</a> sh = m.<a name="centralWidget"></a><a href="qmainwindow.html#4bc1f4">centralWidget</a>()-&gt;sizeHint();    m.<a name="resize"></a><a href="qwidget.html#ff9d07">resize</a>(sh.<a name="width"></a><a href="qsize.html#37cddf">width</a>(),             sh.<a name="height"></a><a href="qsize.html#a35c26">height</a>()+3*m.<a name="statusBar"></a><a href="qmainwindow.html#530937">statusBar</a>()-&gt;height());    app.<a name="setMainWidget"></a><a href="qapplication.html#7ad759">setMainWidget</a>(&amp;m);    m.<a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>("Qt Example - QFD");    m.<a name="show"></a><a href="qmainwindow.html#eb53e3">show</a>();    return app.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();}</pre><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -