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);
}
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);
}
相关文章推荐
- Qt 程序进入界面字体自定义
- Qt 程序启动界面字体大小问题
- 【Qt】Qt之自定义界面(右下角冒泡)【转】
- 让你的 Qt 桌面程序看上去更加 native(三):自定义 style
- Qt 自定义界面,透明与用户风格 一
- Qt之自定义界面(添加自定义标题栏)
- 让你的 Qt 桌面程序看上去更加 native(三):自定义 style 推荐
- Qt同一程序下不同类(不同界面、多个界面)之前同步变量方案
- [ARM Linux] [Qt] 移植Qt程序到ARM Linux上 (包括如何构建专业的PDA界面、phone界面)
- suse10.3缺字体而无法进入图形界面
- QT自定义界面纯QSS
- python+QT designer 做图形化界面EXE程序
- QT程序字体大小和旋转的程序参数设置方式
- 将QT开发的界面程序封装成DLL,在VC中成功调用
- QT 扁平化界面风格,自定义TabWidget控件
- 图形的绘制,如何使用自定义画笔(颜色,线宽,线形)。如何为程序中添加选项菜单和选项设置对话框,如何使用标准颜色对话框,如何使用字体对话框,在选项对话框中实现预览功能。实现选项对话框和窗口类中的数据交换。如何改变对话框和控件的背景色,如何改变控件的文本颜色,
- Qt - 设置程序界面风格(现成的QMacStyle等等)
- [Qt4]程序启动界面设置 + 资源机制
- qt界面程序中相应鼠标QMouseEvent的pos()和gloabalPos()的含义
- Qt中如果通过QStyle自定义能够跨平台的界面控件