LimeReport Forum
General Category | Основное => Discussion | Обсуждение => Topic started by: ann on May 16, 2018, 09:41:38 am
-
Hi all. I am trying to set the font to bold through text item editor. Below is the sample code to set the text color
if($D{tablewidget.intimestatus}==2 && getVariable("colourFlag") == 0){
THIS.fontColor=QColor('green');
}
So is there any code to set the text to bold?. Thanks in advance.
-
Hi!
for example
$S{
var font=QFont("Arial",12,false,75); // Arial, 12 points - size, not italic, bold
if (1)
THIS.font=font;
"klop";
}
-
Hey Subst, you save my day :) the solution work. Thank you very much.
-
Hi!
If you want to modify existing font, you can write font helper then register it in script engine and use it in script.
For example:
class ScriptFontHelper: public QObject{
Q_OBJECT
public:
ScriptFontHelper(QObject* parent = 0):QObject(parent){}
Q_INVOKABLE QFont setBold(QFont font, bool bold){ font.setBold(bold); return font;}
Q_INVOKABLE QFont setItalic(QFont font, bool italic){ font.setItalic(italic); return font;}
};
.....
ScriptFontHelper* fontHelper = new ScriptFontHelper(this);
QScriptValue jsFontHelper = report->scriptManager()->scriptEngine()->newQObject(fontHelper);
report->scriptManager()->scriptEngine()->globalObject().setProperty("FontHelper", jsFontHelper);
in script
$S{THIS.font = FontHelper.setBold(THIS.font,true);""}
Test
-
Subst Why 75 instead true ? :o
-
Hi Arin Alex, thanks for the suggestion. Does the script perform better? Or else I will stick to current code because script seems like complex to me :P
-
My solution is more universal :)
If you write THIS.font=QFont("Arial",12,false,true); it will always Arial,12 independently from TextItem font settings.
But you can use both methods as you wish :)
-
To Alex
Constant Value Description
QFont::Thin 0 0
QFont::ExtraLight 12 12
QFont::Light 25 25
QFont::Normal 50 50
QFont::Medium 57 57
QFont::DemiBold 63 63
QFont::Bold 75 75
QFont::ExtraBold 81 81
QFont::Black 87 87
And in script work fine QFont(const QString &family, int pointSize = -1, bool italic = false, int weight = -1) instead QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false). I don't know why. Empirical way
-
My solution is more universal :)
If you write THIS.font=QFont("Arial",12,false,true); it will always Arial,12 independently from TextItem font settings.
But you can use both methods as you wish :)
I see. Currently I do not need a versatile build yet. But still thank you for the suggestion, might use it next time.