drawfont.cpp~
来自「几个qt-linux的练习小程序」· CPP~ 代码 · 共 53 行
CPP~
53 行
#include "drawfont.h"
DrawWidget::DrawWidget()
{
draw = new Drawwidget(this);// draw->ReSize(750, 550); draw->SetBackGroundColor(green);// update();
resize(800, 600);
}
/*绘制字体*/
void DrawWidget::drawFonts( QPainter *p )
{
static const char *fonts[] = { "Helvetica", "Courier", "Times", 0 };
static int sizes[] = { 10, 12, 18, 24, 36, 0 };
int f = 0;
int y = 0;
while ( fonts[f] ) {
int s = 0;
while ( sizes[s] ) {
QFont font( fonts[f], sizes[s] );
p->setFont( font );
QFontMetrics fm = p->fontMetrics();
y += fm.ascent();
p->drawText( 10, y, "This is Draw Fonts funtions!" );
y += fm.descent();
s++;
}
f++;
}
}
void DrawWidget::drawIt( QPainter *p )
{
drawFonts(p);
}
void DrawWidget::paintEvent( QPaintEvent *)
{
QPainter paint( draw );
drawIt( &paint );
}
int main( int argc, char **argv )
{
QApplication app( argc, argv );
DrawWidget draw;
app.setMainWidget( &draw );
draw.setCaption("Qt");
draw.show();
return app.exec();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?