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. How to Set Font to all Application
Forum Updated to NodeBB v4.3 + New Features

How to Set Font to all Application

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 6.8k 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.
  • T Offline
    T Offline
    TheCipo76
    wrote on 19 Jan 2019, 13:44 last edited by TheCipo76
    #1

    Hi,
    in my application i have to allow user to choose Font

    in mainwindows i call fontdialog()

    now how i can set selected font to all form (and all contents of all form)?

    i've tried with:

    QFont V ("Verdana", 14);
    QApplication::setFont(V);
    

    but don't works (menubar was not changed correctly for example)

    i've also tried with:

     ui->menuBar->setStyleSheet("QMenuBar { font-family:Verdana; font-size:12px;}" "QMenuBar::item { font-family:Verdana; font-size:12px;}" "QMenuBar::item:selected { font-family:Verdana; font-size:12px;}");
    
    

    but don't works too (don't works for Action)

    this solution works but i don't want to change font one by one (moreover don't works for Action):

    bool ok;
     QFont Carattere = QFontDialog::getFont(&ok, this);
     if (ok) {
         V = Carattere;
         ui->menuBar->setFont(V);
         ui->menuFile->setFont(V);
         ui->menuOrdini->setFont(V);
         ui->menuModifica->setFont(V);
         ui->menuRegistra->setFont(V);
         ui->menuFornitore->setFont(V);
         ui->menuInserisci->setFont(V);
         ui->menuMagazzino->setFont(V);
         ui->menuAnagrafica->setFont(V);
         ui->menuProduzione->setFont(V);
         ui->menuda_Clienti->setFont(V);
         ui->menuCambia->setFont(V);
    }
    else {
        return;
    }
    

    any ideas?

    R 1 Reply Last reply 19 Jan 2019, 17:05
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 19 Jan 2019, 16:26 last edited by
      #2

      Did you try with QApplication setFont method ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      T 1 Reply Last reply 19 Jan 2019, 16:54
      0
      • D dheerendra
        19 Jan 2019, 16:26

        Did you try with QApplication setFont method ?

        T Offline
        T Offline
        TheCipo76
        wrote on 19 Jan 2019, 16:54 last edited by
        #3

        @dheerendra Yes, it's the first code i've posted up

        1 Reply Last reply
        0
        • T TheCipo76
          19 Jan 2019, 13:44

          Hi,
          in my application i have to allow user to choose Font

          in mainwindows i call fontdialog()

          now how i can set selected font to all form (and all contents of all form)?

          i've tried with:

          QFont V ("Verdana", 14);
          QApplication::setFont(V);
          

          but don't works (menubar was not changed correctly for example)

          i've also tried with:

           ui->menuBar->setStyleSheet("QMenuBar { font-family:Verdana; font-size:12px;}" "QMenuBar::item { font-family:Verdana; font-size:12px;}" "QMenuBar::item:selected { font-family:Verdana; font-size:12px;}");
          
          

          but don't works too (don't works for Action)

          this solution works but i don't want to change font one by one (moreover don't works for Action):

          bool ok;
           QFont Carattere = QFontDialog::getFont(&ok, this);
           if (ok) {
               V = Carattere;
               ui->menuBar->setFont(V);
               ui->menuFile->setFont(V);
               ui->menuOrdini->setFont(V);
               ui->menuModifica->setFont(V);
               ui->menuRegistra->setFont(V);
               ui->menuFornitore->setFont(V);
               ui->menuInserisci->setFont(V);
               ui->menuMagazzino->setFont(V);
               ui->menuAnagrafica->setFont(V);
               ui->menuProduzione->setFont(V);
               ui->menuda_Clienti->setFont(V);
               ui->menuCambia->setFont(V);
          }
          else {
              return;
          }
          

          any ideas?

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 19 Jan 2019, 17:05 last edited by
          #4

          @TheCipo76
          generally fonts propagate down to descendant child widgets (see this)

          Are you setting fonts via stylesheet in your application?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          T 1 Reply Last reply 19 Jan 2019, 22:03
          0
          • N Offline
            N Offline
            nina22
            Banned
            wrote on 19 Jan 2019, 18:57 last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • R raven-worx
              19 Jan 2019, 17:05

              @TheCipo76
              generally fonts propagate down to descendant child widgets (see this)

              Are you setting fonts via stylesheet in your application?

              T Offline
              T Offline
              TheCipo76
              wrote on 19 Jan 2019, 22:03 last edited by TheCipo76
              #6

              @raven-worx No i don't have used stylesheet

              i need to allow font selection because my application works both on os x than windows..

              i have already read this article today ;)

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TheCipo76
                wrote on 21 Jan 2019, 08:15 last edited by
                #7

                with a fontdialog i can set the QApplication::font

                at the moment i have to set the QApplication::font to every widget one by one eg:

                ui->label->setFont(QApplication::Font());
                

                and when i open a dialog i have to do the same operation to all form widget..

                i'm looking to something faster / easier

                R 1 Reply Last reply 21 Jan 2019, 08:21
                0
                • T TheCipo76
                  21 Jan 2019, 08:15

                  with a fontdialog i can set the QApplication::font

                  at the moment i have to set the QApplication::font to every widget one by one eg:

                  ui->label->setFont(QApplication::Font());
                  

                  and when i open a dialog i have to do the same operation to all form widget..

                  i'm looking to something faster / easier

                  R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 21 Jan 2019, 08:21 last edited by
                  #8

                  @TheCipo76
                  since you read the article, you are aware that setting the font explicitly (manually or via stylesheet) prevents font propagation (Qt::WA_SetFont attribute)?!

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  T 1 Reply Last reply 21 Jan 2019, 08:30
                  2
                  • R raven-worx
                    21 Jan 2019, 08:21

                    @TheCipo76
                    since you read the article, you are aware that setting the font explicitly (manually or via stylesheet) prevents font propagation (Qt::WA_SetFont attribute)?!

                    T Offline
                    T Offline
                    TheCipo76
                    wrote on 21 Jan 2019, 08:30 last edited by TheCipo76
                    #9

                    @raven-worx yes.. i'm fix it with this:

                    void MainWindow::updateAllWidgets()
                    {
                        foreach (QWidget *widget, QApplication::allWidgets()) {
                            widget->setFont(QApplication::font());
                            widget->update();
                        }
                    }
                    

                    But don't works on Menu Action

                    1 Reply Last reply
                    0

                    1/9

                    19 Jan 2019, 13:44

                    • Login

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