Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. change font of stackwidget
Forum Updated to NodeBB v4.3 + New Features

change font of stackwidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
30 Posts 5 Posters 6.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS SGaist

    QFont doesn't take a path as parameter but the family name.

    Use QFontDatabase to load your custom font, build the QFont object using the correct family name and then set it on QApplication.

    zhmhZ Offline
    zhmhZ Offline
    zhmh
    wrote on last edited by
    #9

    @SGaist can you show me with code?
    I used the qfontdatabase at first an doesn’t work!

    RatzzR 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #10

      Then show the current code you use.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • zhmhZ zhmh

        @SGaist can you show me with code?
        I used the qfontdatabase at first an doesn’t work!

        RatzzR Offline
        RatzzR Offline
        Ratzz
        wrote on last edited by
        #11

        @zhmh said in change font of stackwidget:

        I used the qfontdatabase at first an doesn’t work!

        Can you check if addApplicationFont function returns -1 ?
        as mentioned here

        --Alles ist gut.

        zhmhZ 1 Reply Last reply
        2
        • RatzzR Ratzz

          @zhmh said in change font of stackwidget:

          I used the qfontdatabase at first an doesn’t work!

          Can you check if addApplicationFont function returns -1 ?
          as mentioned here

          zhmhZ Offline
          zhmhZ Offline
          zhmh
          wrote on last edited by zhmh
          #12

          @Ratzz yes I checked it before, this is

          int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf");
               qDebug()<< fnt;
          

          returns 0 to me!

          RatzzR 1 Reply Last reply
          0
          • zhmhZ zhmh

            @Ratzz yes I checked it before, this is

            int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf");
                 qDebug()<< fnt;
            

            returns 0 to me!

            RatzzR Offline
            RatzzR Offline
            Ratzz
            wrote on last edited by Ratzz
            #13

            @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 ?

            --Alles ist gut.

            zhmhZ 1 Reply Last reply
            1
            • RatzzR Ratzz

              @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 ?

              zhmhZ Offline
              zhmhZ Offline
              zhmh
              wrote on last edited by
              #14

              @Ratzz

              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();
              }
              
              RatzzR 1 Reply Last reply
              0
              • zhmhZ zhmh

                @Ratzz

                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();
                }
                
                RatzzR Offline
                RatzzR Offline
                Ratzz
                wrote on last edited by
                #15

                @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

                --Alles ist gut.

                zhmhZ 1 Reply Last reply
                0
                • RatzzR Ratzz

                  @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

                  zhmhZ Offline
                  zhmhZ Offline
                  zhmh
                  wrote on last edited by
                  #16

                  @Ratzz how ?

                  int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf");
                  QString family = QFontDatabase::applicationFontFamilies(fnt).at(0);
                   w.setFont(family);
                  

                  is it true?

                  RatzzR 1 Reply Last reply
                  0
                  • zhmhZ zhmh

                    @Ratzz how ?

                    int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf");
                    QString family = QFontDatabase::applicationFontFamilies(fnt).at(0);
                     w.setFont(family);
                    

                    is it true?

                    RatzzR Offline
                    RatzzR Offline
                    Ratzz
                    wrote on last edited by
                    #17

                    @zhmh said in change font of stackwidget:

                    is it true?

                    Yes. Does it work that way?

                    --Alles ist gut.

                    zhmhZ 1 Reply Last reply
                    0
                    • RatzzR Ratzz

                      @zhmh said in change font of stackwidget:

                      is it true?

                      Yes. Does it work that way?

                      zhmhZ Offline
                      zhmhZ Offline
                      zhmh
                      wrote on last edited by
                      #18

                      @Ratzz No :(

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #19

                        Where did you get that font from ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        zhmhZ 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          Where did you get that font from ?

                          zhmhZ Offline
                          zhmhZ Offline
                          zhmh
                          wrote on last edited by
                          #20

                          @SGaist font work with other program

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #21

                            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.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            zhmhZ 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              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.

                              zhmhZ Offline
                              zhmhZ Offline
                              zhmh
                              wrote on last edited by
                              #22

                              @SGaist here you are: https://fonts2u.com/irannastaliq.font

                              RatzzR 1 Reply Last reply
                              0
                              • zhmhZ zhmh

                                @SGaist here you are: https://fonts2u.com/irannastaliq.font

                                RatzzR Offline
                                RatzzR Offline
                                Ratzz
                                wrote on last edited by Ratzz
                                #23

                                @zhmh
                                I tried same font an QStackedWidget with QPushButton in it and seems fine for me.

                                    QStringList list= QFontDatabase::applicationFontFamilies(fnt);
                                    QFont nastaliq(list.at((0)));
                                    w.setFont(nastaliq);
                                

                                alt text

                                --Alles ist gut.

                                zhmhZ 1 Reply Last reply
                                3
                                • RatzzR Ratzz

                                  @zhmh
                                  I tried same font an QStackedWidget with QPushButton in it and seems fine for me.

                                      QStringList list= QFontDatabase::applicationFontFamilies(fnt);
                                      QFont nastaliq(list.at((0)));
                                      w.setFont(nastaliq);
                                  

                                  alt text

                                  zhmhZ Offline
                                  zhmhZ Offline
                                  zhmh
                                  wrote on last edited by zhmh
                                  #24

                                  @Ratzz I don't know why, but it's not work for me

                                  RatzzR mrjjM 2 Replies Last reply
                                  0
                                  • zhmhZ zhmh

                                    @Ratzz I don't know why, but it's not work for me

                                    RatzzR Offline
                                    RatzzR Offline
                                    Ratzz
                                    wrote on last edited by Ratzz
                                    #25

                                    @zhmh

                                    Can you show me a minimal sample/code with which I can reproduce your problem?

                                    --Alles ist gut.

                                    zhmhZ 1 Reply Last reply
                                    1
                                    • zhmhZ zhmh

                                      @Ratzz I don't know why, but it's not work for me

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #26

                                      @zhmh
                                      Hi, so buttons keep their normal font or in what
                                      way does it not work?

                                      zhmhZ 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

                                        @zhmh
                                        Hi, so buttons keep their normal font or in what
                                        way does it not work?

                                        zhmhZ Offline
                                        zhmhZ Offline
                                        zhmh
                                        wrote on last edited by
                                        #27

                                        @mrjj said in change font of stackwidget:

                                        buttons keep their normal font

                                        Hi,buttons keep their normal font

                                        1 Reply Last reply
                                        0
                                        • RatzzR Ratzz

                                          @zhmh

                                          Can you show me a minimal sample/code with which I can reproduce your problem?

                                          zhmhZ Offline
                                          zhmhZ Offline
                                          zhmh
                                          wrote on last edited by zhmh
                                          #28

                                          @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>&lt; قبلی</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>بعدی &gt;</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>&lt;قبلی</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>
                                          
                                          RatzzR 1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved