How include "qfont" in "qlabel" ??
-
I can't understand why I can't transfer the font to the label
.h
#include <QFont> ... class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); ... // подстраиваемый шрифт label QFont* font; int height_monitor {0}; int width_monitor {0}; ... }
.cpp
#include "mainwindow.h" #include "./ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); // тут настраиваю и объявляю элементы font = new QFont(); ... } void MainWindow::resizeEvent(QResizeEvent *e) { height_monitor= e->size().height(); width_monitor = e->size().width(); font->setPointSize((height_monitor*width_monitor)/4); ui->label->setFont(font); // вот тут не работает !!!!! }
-
@timob256 said in How include "qfont" in "qlabel" ??:
I did not understand which command to write to make it work
Open documentation for setFont: https://doc.qt.io/qt-6/qwidget.html#font-prop
As you can clearly see setFont does not take a pointer to QFont, but you're trying to give it a pointer. This is basic C++ knowledge.
Change to:ui->label->setFont(*font);
Or, even better, don't declare font as pointer...
-
@timob256 said in How include "qfont" in "qlabel" ??:
I did not understand which command to write to make it work
Open documentation for setFont: https://doc.qt.io/qt-6/qwidget.html#font-prop
As you can clearly see setFont does not take a pointer to QFont, but you're trying to give it a pointer. This is basic C++ knowledge.
Change to:ui->label->setFont(*font);
Or, even better, don't declare font as pointer...
-