qt - QPushButton icon maximize on resize event -
i have question resizing icon on qpushbutton. target system qt 4.8.6 on linux. using qpushbutton create buttons icons only, no text. have icon large possible centered on button including margin.
i not want button size adapt image size, want image size adapt button size, while button size adapts automaticly gui size through qgridlayout or manually resizing.
when creating button, icon loaded small within middle:
const qstring filename = "bitmaps/btn.png"; if( !qfile( filename ).exists() ) { qdebug() << "file not found: " << filename; } const qpixmap pixmap = qpixmap( filename ); m_btn = new qpushbutton( qicon( pixmap ), "", ); when resizing through manual setting, icon not scale:
m_btn->setgeometry( qrect( 100, 100, 50, 50 ) ); to icon size rescaled need manually call seticonsize(). can call within resize event of instanciating widget. handling margin still has calculated manually.
m_btn->seticonsize( qsize( ( m_btn->size().width() - 12 ), ( m_btn->size().height() - 12 ) ) ); but, qt documentation there stylesheet based layout thing called "the box model" applied qpushbutton well.
http://doc.qt.io/qt-4.8/stylesheet-customizing.html#box-model
so question is, how configure push button icon fill "content" area (marked grey in above document). possibly how configure it, icon resizes automaticly? appreciated :-)
Comments
Post a Comment