c++ - Qt set common background for all dialog boxes -
i working on developing qt 5 widgets desktop application want give common background windows , dialog boxes pop up. problem each window have specify same piece of code on , on again load same background. using paint
function override not distort background when window resized. here's code:
settingsdialog::settingsdialog(qwidget *parent) : qdialog(parent), ui(new ui::settingsdialog) { ui->setupui(this); pixmapbg.load(":/images/google-material-design-wallpaper-10.jpg"); } void settingsdialog::paintevent(qpaintevent *pe) { qpixmap pixmapbgl = pixmapbg.scaled(this->size()); qpalette palette; palette.setbrush(qpalette::background, pixmapbgl); this->setpalette(palette); }
is there way accommodate in qt using single file rather mentioning each window?
yes, can! have provide own stylesheet, or initialize application calling qapplication::setstylesheet(stylename).
follow comment: setstylesheet
quickest approach, i.e.
qapp->setstylesheet("qdialog, qmessagebox {background-image: url(:/images/google-material-design-wallpaper-10.jpg);}");
assuming have valid qapplication reference qapp
. note can refer custom subclasses well, if want refine scope of stylesheet.
Comments
Post a Comment