简体   繁体   English

Qt中的字体编辑器小部件

[英]Font editor widget in Qt

Qt Creator provides an editor for setting QLable style ( CSS for label font style primarily): Qt Creator提供了一个用于设置QLable样式的编辑器( CSS主要用于标签字体样式): 在此处输入图片说明

I would like to do the same thing in my Qt application: be able to call a Qt component/system font editor with a font style argument passed and get a new style when a user finishes editing(2). 我想在我的Qt应用程序中做同样的事情:能够调用带有传递的字体样式参数的Qt组件/系统字体编辑器,并在用户完成编辑后获得新样式(2)。

Simplified code: 简化代码:

Qlabel qlabel;
QFontEditor fontEditor;
fontEditor.setFontStyle(qlabel.getStyle());
fontEditor.show();
qlabel.setStyle(fontEditor.getStyle());

I wonder if there is anything in Qt that can be used as I have spent two days looking for a component. 我想知道Qt是否可以使用任何东西,因为我花了两天时间寻找组件。 The only one I have spotted is the one really used in Qt Creator project but it seems to be hard to incorporate to my application: 我发现的唯一一个是在Qt Creator项目中真正使用过的,但似乎很难将其集成到我的应用程序中:

https://github.com/qtproject/qt-creator/blob/51bb52139c479cca2dae82eb08aeb8d04718fca1/src/plugins/texteditor/fontsettings.h https://github.com/qtproject/qt-creator/blob/51bb52139c479cca2dae82eb08aeb8d04718fca1/src/plugins/texteditor/fontsettings.h

The QFontDialog class provides a dialog widget for selecting a font. QFontDialog类提供用于选择字体的对话框小部件。

bool ok;
QFont font = QFontDialog::getFont(&ok);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM