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.7k 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.
  • TheCipo76T Offline
    TheCipo76T Offline
    TheCipo76
    wrote on 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?

    raven-worxR 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Did you try with QApplication setFont method ?

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

      TheCipo76T 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Did you try with QApplication setFont method ?

        TheCipo76T Offline
        TheCipo76T Offline
        TheCipo76
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • TheCipo76T TheCipo76

          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?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on 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

          TheCipo76T 1 Reply Last reply
          0
          • N Offline
            N Offline
            nina22
            Banned
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • raven-worxR raven-worx

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

              Are you setting fonts via stylesheet in your application?

              TheCipo76T Offline
              TheCipo76T Offline
              TheCipo76
              wrote on 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
              • TheCipo76T Offline
                TheCipo76T Offline
                TheCipo76
                wrote on 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

                raven-worxR 1 Reply Last reply
                0
                • TheCipo76T TheCipo76

                  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

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on 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

                  TheCipo76T 1 Reply Last reply
                  2
                  • raven-worxR raven-worx

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

                    TheCipo76T Offline
                    TheCipo76T Offline
                    TheCipo76
                    wrote on 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

                    • Login

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