您的位置:首页 > 编程语言 > Qt开发

Qt 程序进入界面字体自定义

2012-12-06 10:46 483 查看
最近在写一个QT应用程序,昨天准备加上程序启动界面,类型vs那种,本来很简单如下:



int main(int argc, char *argv[])

{

QApplication app(argc, argv);

QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));

QPixmap pixmap("init.jpg");

QSplashScreen *splash = new QSplashScreen(pixmap);

splash->show();

//显示信息

splash->showMessage("Wait...");

qApp->processEvents();//This is used to accept a click on the screen so that user can cancel the screen

QMain window;

window.setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px}");

window.show();

//图片一直显示到mainWin加载完成

splash.finish(&window);

delete splash;

return app.exec();

}

程序没有问题,但是文字大小不可调,继续查文档,发现以下函数:void QSplashScreen::drawContents ( QPainter * painter )

该函数可以根据用户自定义的情况下通过QPainter在程序进入时调整显示内容,但该函数是虚函数,且是protected的

所以还是进行类继承,并对以上的这个函数进行重写,Reimplement this function if you want to do your own drawing on the splash screen.

class Test:public QSplashScreen

{

public:

Test();

void drawContents(QPainter *painter);

};

Test::Test()

{

//QMessageBox::information(NULL,tr("Path"),tr("You Selected"));

//QPainter painter(this);

}

void Test::drawContents(QPainter *painter)

{

painter->setFont(QFont("Helvetica", 18, QFont::Bold));//这个地方可以自定义你想要的效果,如字体大小,字体类型,或者可以通过painter绘制图形都ok

QSplashScreen::drawContents(painter);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐