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()?

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.6k Views
  • 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 1 Mar 2019, 21:45 last edited by Yash001 3 Jan 2019, 23:11
    #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 ?

    P 1 Reply Last reply 3 Mar 2019, 23:34
    1
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 2 Mar 2019, 04:34 last edited by
      #2

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

      Y 1 Reply Last reply 4 Mar 2019, 21:13
      0
      • Y Yash001
        1 Mar 2019, 21:45
        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 ?

        P Offline
        P Offline
        Pl45m4
        wrote on 3 Mar 2019, 23:34 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 4 Mar 2019, 21:09
        0
        • P Pl45m4
          3 Mar 2019, 23:34

          @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 4 Mar 2019, 21:09 last edited by
          #4

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

          1 Reply Last reply
          0
          • K Kent-Dorfman
            2 Mar 2019, 04:34

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

            Y Offline
            Y Offline
            Yash001
            wrote on 4 Mar 2019, 21:13 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
            • K Offline
              K Offline
              Kent-Dorfman
              wrote on 4 Mar 2019, 21:22 last edited by Kent-Dorfman 3 Apr 2019, 21:23
              #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

              6/6

              4 Mar 2019, 21:22

              • Login

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