c++ - QLabel with automatic scaling -


i need qt widget displays plain text scales automatically. means when resize window has widget in layout, font size adjusted size of widget display text in font big possible fit in size layout dictates. word wrap bonus.

i think, has implemented such widget, couldn't google it.

you on resize event of window:

void mainwindow::resizeevent(qresizeevent*) {     qfont f = label->font(); //get label font      qfontmetrics metrics(f);     qsize size = metrics.size(0, label->text()); //get size of text     float factorw = label->width() / (float)size.width(); //get width factor     float factorh = label->height() / (float)size.height(); //get height factor      float factor = qmin(factorw, factorh); //to fit contents in screen select factor                                            //the minimum factor between width , height      f.setpointsizef(f.pointsizef() * factor); //set font size     label->setfont(f); //set adjusted font label } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -