简体   繁体   English

每个QFont都有新的QFontDialog吗?

[英]New QFontDialog for each QFont?

How can I change different fonts for 2 (or more) QFont, if I have only one QFontDialog? 如果我只有一个QFontDialog,如何更改2个(或更多)QFont的不同字体? How can I do it more efficient? 如何提高效率? Creating new QFontDialog for each QFont will be very stupid, I think. 我认为为每个QFont创建新的QFontDialog将非常愚蠢。

If you want to do this simultaneously, you need to add two QFontDialog to your form. 如果要同时执行此操作,则需要在窗体中添加两个QFontDialog。 Otherwise you can use the one QFontDialog object and simply set current font using setCurrentFont() before showing the dialog. 否则,您可以使用一个QFontDialog对象,并在显示对话框之前简单地使用setCurrentFont()设置当前字体。

So, creating QFontDialog for each QFont isn't optimal method (too many - over 100 - QFont-s and QFontDialog-s will take a lot of memory). 因此,为每个QFont创建QFontDialog并不是最佳方法(太多-超过100个-QFont-s和QFontDialog-s将占用大量内存)。 More efficient - creating specific SIGNAL-S and SLOT-s for QFontDialog and QFont (in my situation it is FontChooser (modified QLineEdit), that recieve QFont info from QFontDialog) like this below: 效率更高-为QFontDialog和QFont创建特定的SIGNAL-S和SLOT-s(在我的情况下是FontChooser(修改后的QLineEdit),它从QFontDialog接收QFont信息),如下所示:

QObject::connect(&fontdialog, SIGNAL(font_selected(FontChooser *, const QFont &)), &fontchooser, SLOT(set_font_info(FontChooser *, const QFont &))); 
QObject::connect(&fontchooser, SIGNAL(clicked(FontChooser *, const QFont &)), &fontdialog, SLOT(show(FontChooser *, const QFont &)));

When I posted this question, I thought, that Qt have some easy func-s to do that. 当我发布这个问题时,我以为Qt有一些简单的功能可以做到这一点。 May be I am wrong? 可能是我错了吗? :) Problem was solved. :)问题解决了。 Thx. 谢谢。

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

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