📄 drawfont.cpp
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -