PDA

View Full Version : Why is QDateEdit font point size is limited to 24 pt?



shijiaguo
28th February 2013, 02:07
Hi all,
I was trying to enlarge my font point size of texts in a QDateEdit. However, I found out that the font size is always set to be 24 if it's more than 24. If it's set to be less than 24, it can be successfully set to be what it should be. It's weird to me since I really want to increase the size of my editable date and time. Is there any workaround?
Please help me! Thanks!

wysota
28th February 2013, 02:50
Please provide a minimal compilable example reproducing the problem. I can set whatever font size I want on my date edit.

shijiaguo
28th February 2013, 14:24
Hi wysota, thanks for your reply! As follows are my codes:

static QFont font_mb("Helvetica", 10, QFont::Bold);

setDateEdit->setStyle(new QWindowsStyle); //setDateEdit is a QDateEdit created in designer already, so no need to initialize here again
QFontInfo qfontfont = setDateEdit->fontInfo();
qDebug()<<"font size is:"<<qfontfont.pointSize();
setDateEdit->setFont(font_mb);//set the font
QFontInfo qfontfont2 = setDateEdit->fontInfo();
qDebug()<<"font size is:"<<qfontfont2.pointSize();

So if I set the font to 10 the output will be
font size is: 10
font size is: 10

If I then set the font to 30, the output is:
font size is: 10
font size is: 24

I'm using qt 4.3.3. Is there something I did wrong or it's the version issue?
Again, thank you so much for your help!

wysota
28th February 2013, 14:58
Why are you using a static font object? Where did you declare it? How are you changing the font size? We can't see that in the code you posted.

shijiaguo
28th February 2013, 15:29
Hi wysota,
The static shouldn't matter. I just kept it since it's how the code was written by someone else. I tried without the static it gives me the same thing.

setDateEdit->setFont(font_mb);//set the font

This is where I change the font of the setDateEdit object.
Unfortunately I can't see anything problematic here..

wysota
28th February 2013, 16:22
setDateEdit->setFont(font_mb);//set the font

This is where I change the font of the setDateEdit object.
Unfortunately I can't see anything problematic here..

I asked where you change the font size. Your font_mb object is set to pointSize of "10".

shijiaguo
28th February 2013, 16:26
Oh I just ran it again. Change the line
static QFont font_mb("Helvetica", 10, QFont::Bold);
to be:
static QFont font_mb("Helvetica", 30, QFont::Bold);

Sorry I wasn't clear before. Essentially I'm trying to SET the font to a larger point-size, not CHANGE the font during execution.
Could you please share how you set the font? Thanks very much!

wysota
28th February 2013, 16:42
Could you please share how you set the font? Thanks very much!
I launched Qt Designer, dropped a date time edit on the form, changed its font to something larger than 24pt and previewed the form.

shijiaguo
28th February 2013, 16:46
If you only preview the form, it looks fine. But when you actually compile it and run it, it gives you what I described before.

wysota
28th February 2013, 16:57
If you only preview the form, it looks fine. But when you actually compile it and run it, it gives you what I described before.

No. It gives me the same I had when previewing the form.


#include <QtGui>

int main(int argc, char **argv) {
QApplication app(argc, argv);
QDateEdit de;
QFont f = app.font();
f.setPointSize(48);
de.setFont(f);
de.show();
return app.exec();
}

shijiaguo
28th February 2013, 18:47
hmm. Interesting. Thanks for your effort wysota. That might be due to some issue of my compiler. Even though I change the font from the designer, it still eliminates the setting of >24 pt font.
I'm using arm_v5t_le-gcc. Anybody know that affects the font settings?

wysota
28th February 2013, 22:16
Did you build and test the example code from my last post? Does it work or not?