Unsolved change font of stackwidget
-
@Ratzz yes I checked it before, this is
int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf"); qDebug()<< fnt;
returns 0 to me!
-
@zhmh said in change font of stackwidget:
returns 0 to me
Which means the fond is loaded properly.
Use http://doc.qt.io/qt-5/qfontdatabase.html#applicationFontFamilies to get the font and set back to application.
Can you show the code ?
-
int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf"); qDebug() << fnt << QFontDatabase::applicationFontFamilies(fnt);
returns: 0 ("Nastaliq")
@Ratzz said in change font of stackwidget:
Can you show the code ?
this is my main.cpp:
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf"); qDebug() << fnt << QFontDatabase::applicationFontFamilies(fnt); QFont nastaliq("Nastaliq",20,QFont::Normal); w.setFont(nastaliq); w.show(); return a.exec(); }
-
@zhmh said in change font of stackwidget:
QFont nastaliq("Nastaliq",20,QFont::Normal);
You should set the font which you got from the http://doc.qt.io/qt-5/qfontdatabase.html#applicationFontFamilies
-
@Ratzz how ?
int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf"); QString family = QFontDatabase::applicationFontFamilies(fnt).at(0); w.setFont(family);
is it true?
-
-
@Ratzz No :(
-
Where did you get that font from ?
-
@SGaist font work with other program
-
That's beside the question. If people knows where to download the font, they can test it on their system to find out what's going wrong.
-
@SGaist here you are: https://fonts2u.com/irannastaliq.font
-
@zhmh
I tried same font anQStackedWidget
withQPushButton
in it and seems fine for me.QStringList list= QFontDatabase::applicationFontFamilies(fnt); QFont nastaliq(list.at((0))); w.setFont(nastaliq);
-
@Ratzz I don't know why, but it's not work for me
-
Can you show me a minimal sample/code with which I can reproduce your problem?
-
@zhmh
Hi, so buttons keep their normal font or in what
way does it not work? -
@mrjj said in change font of stackwidget:
buttons keep their normal font
Hi,buttons keep their normal font
-
@Ratzz
cpp:Healthy::Healthy(QWidget *parent) : QMainWindow(parent), ui(new Ui::Healthy) { ui->setupUi(this); //--------------------------for changing the page-------------------------------------// connect(ui->back2, &QAbstractButton::clicked,[=](){ui->stackedWidget->setCurrentIndex(0);}); connect(ui->doctor, &QAbstractButton::clicked,[=](){ui->stackedWidget->setCurrentIndex(1);}); connect(ui->back3, &QAbstractButton::clicked,[=](){ui->stackedWidget->setCurrentIndex(1);}); connect(ui->next1, &QAbstractButton::clicked,[=](){ui->stackedWidget->setCurrentIndex(2);}); //---------------------------------close GUI-----------------------------------------// connect(ui->exit, SIGNAL(clicked()), this, SLOT(close())); } Healthy::~Healthy() { delete ui; }
main:
int main(int argc, char *argv[]) { QApplication a(argc, argv); Healthy w; int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf"); QStringList list= QFontDatabase::applicationFontFamilies(fnt); QFont nastaliq(list.at((0))); w.setFont(nastaliq); w.show(); return a.exec(); }
ui:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Healthy</class> <widget class="QMainWindow" name="Healthy"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>803</width> <height>485</height> </rect> </property> <property name="windowTitle"> <string>Healthy</string> </property> <property name="styleSheet"> <string notr="true">background-color: rgb(161, 194, 231)</string> </property> <widget class="QWidget" name="centralWidget"> <widget class="QStackedWidget" name="stackedWidget"> <property name="geometry"> <rect> <x>20</x> <y>20</y> <width>761</width> <height>421</height> </rect> </property> <property name="font"> <font> <pointsize>15</pointsize> </font> </property> <property name="styleSheet"> <string notr="true">background-color:rgb(255, 255, 255)</string> </property> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="page"> <widget class="QPushButton" name="doctor"> <property name="geometry"> <rect> <x>190</x> <y>180</y> <width>221</width> <height>91</height> </rect> </property> <property name="styleSheet"> <string notr="true"/> </property> <property name="text"> <string>پزشک</string> </property> </widget> <widget class="QPushButton" name="exit"> <property name="geometry"> <rect> <x>50</x> <y>30</y> <width>81</width> <height>31</height> </rect> </property> <property name="styleSheet"> <string notr="true"/> </property> <property name="text"> <string>خروج</string> </property> </widget> </widget> <widget class="QWidget" name="page_2"> <widget class="QPushButton" name="back2"> <property name="geometry"> <rect> <x>70</x> <y>349</y> <width>101</width> <height>41</height> </rect> </property> <property name="styleSheet"> <string notr="true"/> </property> <property name="text"> <string>< قبلی</string> </property> </widget> <widget class="QPushButton" name="next1"> <property name="geometry"> <rect> <x>600</x> <y>349</y> <width>101</width> <height>41</height> </rect> </property> <property name="styleSheet"> <string notr="true"/> </property> <property name="text"> <string>بعدی ></string> </property> </widget> <widget class="QLineEdit" name="meliCode"> <property name="geometry"> <rect> <x>315</x> <y>130</y> <width>201</width> <height>41</height> </rect> </property> </widget> <widget class="QComboBox" name="gender"> <property name="geometry"> <rect> <x>64</x> <y>120</y> <width>121</width> <height>61</height> </rect> </property> <property name="styleSheet"> <string notr="true"/> </property> <item> <property name="text"> <string>مرد</string> </property> </item> <item> <property name="text"> <string>زن</string> </property> </item> <item> <property name="text"> <string/> </property> </item> </widget> <widget class="QLabel" name="label_2"> <property name="geometry"> <rect> <x>580</x> <y>140</y> <width>61</width> <height>31</height> </rect> </property> <property name="font"> <font> <pointsize>15</pointsize> </font> </property> <property name="text"> <string>کدملی</string> </property> </widget> <widget class="QLabel" name="label_3"> <property name="geometry"> <rect> <x>220</x> <y>50</y> <width>41</width> <height>31</height> </rect> </property> <property name="font"> <font> <pointsize>15</pointsize> </font> </property> <property name="text"> <string>سن</string> </property> </widget> <widget class="QLabel" name="label_4"> <property name="geometry"> <rect> <x>200</x> <y>140</y> <width>71</width> <height>31</height> </rect> </property> <property name="font"> <font> <pointsize>15</pointsize> </font> </property> <property name="text"> <string>جنسبت</string> </property> </widget> <widget class="QLabel" name="label_5"> <property name="geometry"> <rect> <x>560</x> <y>220</y> <width>81</width> <height>31</height> </rect> </property> <property name="font"> <font> <pointsize>15</pointsize> </font> </property> <property name="text"> <string>تاریخ </string> </property> </widget> <widget class="QLineEdit" name="date"> <property name="geometry"> <rect> <x>315</x> <y>210</y> <width>201</width> <height>41</height> </rect> </property> </widget> <widget class="QLineEdit" name="age"> <property name="geometry"> <rect> <x>60</x> <y>50</y> <width>141</width> <height>41</height> </rect> </property> </widget> <widget class="QLineEdit" name="name_line"> <property name="geometry"> <rect> <x>316</x> <y>41</y> <width>201</width> <height>41</height> </rect> </property> </widget> <widget class="QLabel" name="label"> <property name="geometry"> <rect> <x>534</x> <y>47</y> <width>161</width> <height>41</height> </rect> </property> <property name="font"> <font> <pointsize>15</pointsize> </font> </property> <property name="text"> <string>نام و نام خانوادگی</string> </property> </widget> </widget> <widget class="QWidget" name="page_3"> <widget class="QLabel" name="label_6"> <property name="geometry"> <rect> <x>436</x> <y>20</y> <width>141</width> <height>51</height> </rect> </property> <property name="font"> <font> <pointsize>15</pointsize> </font> </property> <property name="text"> <string>سوابق بیماری</string> </property> </widget> <widget class="QCheckBox" name="checkBox"> <property name="geometry"> <rect> <x>260</x> <y>80</y> <width>201</width> <height>71</height> </rect> </property> <property name="font"> <font> <pointsize>20</pointsize> </font> </property> <property name="text"> <string>قلبی عروقی</string> </property> <property name="iconSize"> <size> <width>50</width> <height>50</height> </size> </property> </widget> <widget class="QCheckBox" name="checkBox_2"> <property name="geometry"> <rect> <x>250</x> <y>280</y> <width>201</width> <height>61</height> </rect> </property> <property name="font"> <font> <pointsize>20</pointsize> </font> </property> <property name="text"> <string>قندخون و دیابت</string> </property> </widget> <widget class="QCheckBox" name="checkBox_3"> <property name="geometry"> <rect> <x>290</x> <y>170</y> <width>171</width> <height>81</height> </rect> </property> <property name="font"> <font> <pointsize>20</pointsize> </font> </property> <property name="text"> <string>فشار خون</string> </property> </widget> <widget class="QPushButton" name="back3"> <property name="geometry"> <rect> <x>70</x> <y>349</y> <width>101</width> <height>41</height> </rect> </property> <property name="styleSheet"> <string notr="true"/> </property> <property name="text"> <string><قبلی</string> </property> </widget> </widget> </widget> </widget> <widget class="QMenuBar" name="menuBar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>803</width> <height>25</height> </rect> </property> </widget> <widget class="QToolBar" name="mainToolBar"> <attribute name="toolBarArea"> <enum>TopToolBarArea</enum> </attribute> <attribute name="toolBarBreak"> <bool>false</bool> </attribute> </widget> <widget class="QStatusBar" name="statusBar"/> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/> </ui>
-
@zhmh said in change font of stackwidget:
cpp:
It works for me in Qt 5.9.3 on Win 10.
What platform and Qt you use? -
@Ratzz 1-Qt 5.5.1 on ubuntu 14.04
,2-cross compile Qt 5.6 for raspberry Pi
3-Qt 5.6 on windows 8.1
I check with on windows and linux buttons and comboBox and ...... keep their normal font
as I said before in this specific program I have this problem ,I test with other program and It works