Answer the question
In order to leave comments, you need to log in
Qt. What is point in QFont context?
It seems like it is recommended to use the size in points, not in pixels. It is clear that the size of the point should be dependent on the physical size of the screen. But what is it? 1mm? 1/10 inch? Didn't find it anywhere.
Also, as far as I understand, by default Qt puts system fonts. And I wanted to get the system font size via my_font.pixelSize() in order to set the height of the QLabel (which, oddly enough, is in pixels), but I can't, because it returns -1 due to the default points. Can I somehow solve this problem?
Answer the question
In order to leave comments, you need to log in
One dot (pt) equals 1/72 of an inch. DPI - dots per inch (in this case dots == pixels).
double dpi = QGuiApplication::primaryScreen()->physicalDotsPerInch();
auto pt_to_px = [dpi](double pt) -> double { return pt / 72 * dpi; };
auto px_to_pt = [dpi](double px) -> double { return px * 72 / dpi; };
std::clog << "12 pt is " << pt_to_px(12) << " px" << std::endl;
std::clog << "26 px is " << px_to_pt(26) << " pt" << std::endl;
QFont system_font;
std::clog << "system font size in pt: "
<< system_font.pointSize()
<< "\nsystem font size in px: "
<< pt_to_px(system_font.pointSize()) << std::endl;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question