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 can i increase font size of QLabel with help of Qwidget::setFont()?
Forum Updated to NodeBB v4.3 + New Features

how can i increase font size of QLabel with help of Qwidget::setFont()?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qwidgetqlabelqfont
6 Posts 3 Posters 3.7k Views 3 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.
  • Y Offline
    Y Offline
    Yash001
    wrote on last edited by Yash001
    #1
    QWidget* MainWindowUI::GetSoftwareManual() {
    
    	static QWidget *w = 0;
    
    	if (w != 0) {
    		return w;
    	}
    
    	//w = WDG();
    	w = new QWidget();
    
    	QLabel* lal;
    	// set the horizontal layout into Software Manual Widge
    	QHBoxLayout *lay = NO_SPACING(NO_MARGIN(new QHBoxLayout(w)));
    	lay->addWidget(lal= new QLabel("hello"));
    	
    	
    	QFont f = lal->font();
    	f.setPixelSize(20);
    	f.setPointSize(20);
    	f.setBold(true);
    	lal->setFont(f);
    	
    	return w;
    }
    

    output:
    0_1551476508400_bf9943a7-5012-4b92-a171-60f768062cfe-image.png

    It make text bold but does not increase font size.

    I wanted use Qwidget::setFont and QFont for increasing size of font.

    If i will QTimer then it is increase font size correctly, but it is add flick.

    QTimer::singleShot(1, [=]() {
       	lal->setFont(f);
       });
    

    what is right way to use increasing size of QLabel text ?

    Pl45m4P 1 Reply Last reply
    1
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      so what happens when you go the other direction and shrink the text?

      Y 1 Reply Last reply
      0
      • Y Yash001
        QWidget* MainWindowUI::GetSoftwareManual() {
        
        	static QWidget *w = 0;
        
        	if (w != 0) {
        		return w;
        	}
        
        	//w = WDG();
        	w = new QWidget();
        
        	QLabel* lal;
        	// set the horizontal layout into Software Manual Widge
        	QHBoxLayout *lay = NO_SPACING(NO_MARGIN(new QHBoxLayout(w)));
        	lay->addWidget(lal= new QLabel("hello"));
        	
        	
        	QFont f = lal->font();
        	f.setPixelSize(20);
        	f.setPointSize(20);
        	f.setBold(true);
        	lal->setFont(f);
        	
        	return w;
        }
        

        output:
        0_1551476508400_bf9943a7-5012-4b92-a171-60f768062cfe-image.png

        It make text bold but does not increase font size.

        I wanted use Qwidget::setFont and QFont for increasing size of font.

        If i will QTimer then it is increase font size correctly, but it is add flick.

        QTimer::singleShot(1, [=]() {
           	lal->setFont(f);
           });
        

        what is right way to use increasing size of QLabel text ?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @Yash001

        Why you set Point AND Pixelsize to 20?
        They both do nearly the same. Try it without the "setPixel", as setPoint is device independent.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        Y 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @Yash001

          Why you set Point AND Pixelsize to 20?
          They both do nearly the same. Try it without the "setPixel", as setPoint is device independent.

          Y Offline
          Y Offline
          Yash001
          wrote on last edited by
          #4

          @Pl45m4
          I already tried separately and together both, but none of them work.

          1 Reply Last reply
          0
          • Kent-DorfmanK Kent-Dorfman

            so what happens when you go the other direction and shrink the text?

            Y Offline
            Y Offline
            Yash001
            wrote on last edited by
            #5

            @Kent-Dorfman said in how can i increase font size of QLabel with help of Qwidget::setFont()?:

            when you go the other direction

            do you mean change alignment? Left to Right?

            1 Reply Last reply
            0
            • Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on last edited by Kent-Dorfman
              #6

              no, decrese the font size and see if it works. then you'll know whether you can change font size at all. If it works then that should be a hint as to why you cannot increase the size.

              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