QFont font;
font.setBold(true);
std::cout<<QFontMetrics(font).width("...");
Writed 9.
QFont font;
std::cout<<QFontMetrics(font).width("...");
Writed 12.
Why if font is bold the width is smaller then if font is nobold?
 Novice
					
					
						Novice
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
    
    
    
    
   
    
    
    
    
   QFontMetrics, i can't understand
 QFontMetrics, i can't understand
		QFont font;
font.setBold(true);
std::cout<<QFontMetrics(font).width("...");
Writed 9.
QFont font;
std::cout<<QFontMetrics(font).width("...");
Writed 12.
Why if font is bold the width is smaller then if font is nobold?
 Guru
					
					
						Guru
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: QFontMetrics, i can't understand
 Re: QFontMetrics, i can't understand
		It seems to work OK on my system. Which Qt version and what font do you use?
 Novice
					
					
						Novice
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
    
    
    
    
   
    
    
    
    
   Re: QFontMetrics, i can't understand
 Re: QFontMetrics, i can't understand
		Qt 4.3
I use only this code
And it is writeQt Code:
QFont font2;
std::cout<<QFontMetrics(font2).width("...")<<"\n";
font2.setBold(true);
font2.setItalic(true);
std::cout<<QFontMetrics(font2).width("...");To copy to clipboard, switch view to plain text mode
12
9
 Novice
					
					
						Novice
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
    
    
    
    
   
    
    
    
    
   Re: QFontMetrics, i can't understand
 Re: QFontMetrics, i can't understand
		if i don't use font2.setBold(true);
it is write
12
12
 Guru
					
					
						Guru
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: QFontMetrics, i can't understand
 Re: QFontMetrics, i can't understand
		I've just tried it on windows, and indeed I got 12 and 9, but if you start Qt Designer and compare two labels (one with normal font and second with bold font), you'll see it's a correct result for the default font.
 Novice
					
					
						Novice
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
    
    
    
    
   
    
    
    
    
   Re: QFontMetrics, i can't understand
 Re: QFontMetrics, i can't understand
		it is a bug of the Qt?
 Expert
					
					
						Expert
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Expert
					
					
						Expert
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: QFontMetrics, i can't understand
 Re: QFontMetrics, i can't understand
		Qt Code:
{
ui.setupUi(this);
}To copy to clipboard, switch view to plain text mode
label and label_2 are two QLabels with the same font set. One has normal font and the other has a bold font.
I always get a smaller width for the label with normal font. I tried with several fonts.
What font did you use?
Regards
 Guru
					
					
						Guru
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: QFontMetrics, i can't understand
 Re: QFontMetrics, i can't understand
		No, everything is OK. It's just a property of a font you have used.
ss.png
 Guru
					
					
						Guru
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Expert
					
					
						Expert
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
    
    
    
    
   
    
    
       
    
    
    
    
   Re: QFontMetrics, i can't understand
 Re: QFontMetrics, i can't understand
		Yes, with "..." I get the same result.
But with other font families this seems to be OK.
Anyway, I don't see a real problem even with MS Shell Dlg 2, as long as the dimensions are correct( which they are ).
So, there must be a glitch in the font.
Regards
 Guru
					
					
						Guru
					
					
                                        
					
						
							
								 
							
						
					
					
						 
    
    
       
    
    
    
    
    
    
   
    
    
       
    
    
    
    
  
Bookmarks