QFont font;
font.setPixelSize(m_FontSize);
m_LeftTopCornerLabel->setFont(font);
m_LeftBottomCornerLabel->setFont(font);
QFontMetrics fm(font);
int textHeight = fm.height();
int textWidth = fm.width(m_LeftTopCornerLabel->text());
m_LeftTopCornerLabel->setGeometry(2,0,textWidth,textHeight);
textWidth = fm.width(m_LeftBottomCornerLabel->text());
m_LeftBottomCornerLabel->setGeometry(2,m_Size.height()-textHeight,textWidth,textHeight);
QFont font1;
font1.setPixelSize(m_FontSize*m_FontSizeRatio);
m_CenterCommPriceLabel->setFont(font1);
QFontMetrics fm1(font1);
int commWidth = fm1.width(m_CenterCommPriceLabel->text());
int commHeight = fm1.height();
QFont font2;
font2.setPixelSize(m_FontSize/m_FontSizeRatio);
m_CenterBidAskPriceLabel->setFont(font2);
QFontMetrics fm2(font2);
int bidAskWidth = fm2.width(m_CenterBidAskPriceLabel->text());
int bidAskHeight = fm2.height();
textWidth = ( m_Size.width() - (commWidth + bidAskWidth) ) / 2;
m_CenterCommPriceLabel->setGeometry(textWidth,(m_Size.height()-commHeight)/2,commWidth,commHeight);
m_CenterBidAskPriceLabel->setGeometry(textWidth+commWidth,(m_Size.height()-bidAskHeight)/2,bidAskWidth,bidAskHeight);
注:字体的y值位置指字体的最下端的坐标,而非像其它窗体控件一样,y值指的top值。
评论