QwtPlot Palette overwritten by Qmainwindow stylesheet.
-
Hi,
I set the background color of a QwtPlot. Then I add it to a dock widget, then add the dockwidget to a QMainWindow.
The background color works well until I add a style sheet to the mainwindow as follows:
this->setStyleSheet("QMainWindow::separator {background: rgb(255, 255, 255);width: 2px; height: 2px;}");
I set the background color of the QwtPlot as folows:
@
QPalette pal = palette();
QColor LightBlue;
LightBlue.setRgb(110,180,220,255);
QLinearGradient gradient( 0, 0, 0, 1 );
gradient.setCoordinateMode( QGradient::StretchToDeviceMode );
gradient.setColorAt( 0.0, Qt::white );
gradient.setColorAt( 0.7, LightBlue );
gradient.setColorAt( 1.0, LightBlue );
pal.setBrush( QPalette::Window, gradient );Plot->setPalette( pal );
@
Does anyone know how to overcome this?
I have tried setting the mainwindow stylesheet before and after the QwtPlot palette setting. No change.
Thank you!
-
Hi
when I changed the background color of the QwtPlot I used Stylesheet.
@
QString stytleSheetString1 = " QwtPlot { border: 2px solid %1; border-radius: 10px; background-color: %1; font-size: 11px; }";@
Try to avoid mixing QPalette and StyleSheet.
The ordering when which is used is not guaranteed .As a test, comment the setStylesheet line and add setBrush(Qt::red);
Why don't you use QPalette within the QMainwindow? -
Thank you messi.
I have figured out how to do it now. It was a problem with stylesheet and QPalette.
Just a note, if you want to set the background color of the plot use:
@Plot->canvas()->setStyleSheet(" QwtPlotCanvas { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #dadbde); }");@
Then to change the border around the plot (including the axes and such) use:
@Plot->setStyleSheet(" QwtPlot { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #dadbde); }");@Thanks again.