How to apply colors to a box/subwindow within mainwindow?
-
I have created a QColordialog below is the screenshot where user selects a color and the color should be applied in the below box/subwindow.Please suggest
-
Hi,
What's that "below box/subwindow" ?
-
@SGaist
Hi,
I have put a QMdiArea(it can be anything).When user selects the color the region should be colored correspondingly.Is it possible? -
So it would be the background color ?
There are several possibilities depending on what you are going to use.
The most quick and simple would using a style sheet.
-
@SGaist
the selected color has to be applied to the region below.Please suggest what kind of region should be used to do this.I tried applying stylesheets on mdiarea its not working -
Hi
Stylesheets surely works as i used them a lot :)Can you provide more detail of what you call "the region."
Is it same area, is it many different widgets ?
What do you want to color ?
Its not enough to say "applied to the region below" since the answer depends on what you are really trying :) -
@mrjj
Hi,Thanks for the reply.Its a label.How can I set stylesheets to that label based on users selection from the QColorDialog.
-
@Sherlin-N-G
hi
You would generate the stylesheetstring#include <QColorDialog> QString sheet = R"( QLabel#label { background-color: %1; } )"; void SetColor(QWidget *w ) { if( !w ) return; QColor color = QColorDialog::getColor(Qt::yellow); if( color.isValid() ) { w->setStyleSheet( sheet.arg(color.name()) ); } }
// call it like
SetColor(ui->label);Note label must be called "label" or yo should adjust name in string.