set background for mainwindow and set background color for widgets are coonfused in css.
-
Hi
I set a background for my mainwindow and also set a black background color for all widgets.QWidget , QDialog { background-color:black; } #MainWindow { background-image:url(/pic/img.jpg); }
but in this code the main window does not set background image. and the color of background is white. when I comment the qwidget css. the background image is ok but all my widgets are white.
How can I set css like above css? -
Hi
I set a background for my mainwindow and also set a black background color for all widgets.QWidget , QDialog { background-color:black; } #MainWindow { background-image:url(/pic/img.jpg); }
but in this code the main window does not set background image. and the color of background is white. when I comment the qwidget css. the background image is ok but all my widgets are white.
How can I set css like above css?@MhM93
what happens when you do the following?QWidget , QDialog { background: black; } #MainWindow { background: url(/pic/img.jpg); }
-
@MhM93
ok i understood it this way that the 2 definitions are interfering.
Where is the image file stored? On the file system or in a qrc file?
For FS:background: url("file:///pic/img.jpg");
For qrc:
background: url(":/pic/img.jpg");
-
in the qrc.
in this code the picture is not set for main window background :(this is my code in my css exactly)/*========================================*/ /* QWidget - QDialog */ QWidget , QDialog { background-color:rgb(67,67,67); } #MainWindow { background-image: url(":/myImg/1.jpg"); }
-
in the qrc.
in this code the picture is not set for main window background :(this is my code in my css exactly)/*========================================*/ /* QWidget - QDialog */ QWidget , QDialog { background-color:rgb(67,67,67); } #MainWindow { background-image: url(":/myImg/1.jpg"); }
@MhM93
then you need to prepend:
orqrc://
to your path. -
@MhM93
i don't know your qrc file, so i don't know if that path is correct.
What does the following return?qDebug() << QFile::exists(":/myImg/1.jpg");
-
Hi,
@raven-worx , thanks for reply.qDebug() << QFile::exists(":/myImg/1.jpg");
this code return true;
@m-sue : thanks for reply. I change my code to this. but the picture is not set the background in mainwindow:QWidget , QDialog { background-color:rgb(67,67,67); } #MainWindow { background: url(:/myImg/1.jpg); }
-
Hi,
@raven-worx , thanks for reply.qDebug() << QFile::exists(":/myImg/1.jpg");
this code return true;
@m-sue : thanks for reply. I change my code to this. but the picture is not set the background in mainwindow:QWidget , QDialog { background-color:rgb(67,67,67); } #MainWindow { background: url(:/myImg/1.jpg); }
@MhM93
and now pls try to set it exactly to this:QWidget , QDialog { background: rgb(67,67,67); } #MainWindow { background: url(':/myImg/1.jpg'); }
But most probably you wont see the image because you set it to the main window directly. And it's central widget is covering over it, since you also set a background color for all QWidgets.
-
really thanks @raven-worx for reply. I change the css to this:
QWidget , QDialog { background:rgb(67,67,67); } #MainWindow { background: url(:/myImg/1.jpg); }
all widget set dark, but the picture is not set in the main window background.
:( -
really thanks @raven-worx for reply. I change the css to this:
QWidget , QDialog { background:rgb(67,67,67); } #MainWindow { background: url(:/myImg/1.jpg); }
all widget set dark, but the picture is not set in the main window background.
:(@MhM93
did you read my note at the end of my last post? -
so how can I do some thong like that? I want to set back ground image for some widget and the other widget i like to be dark. How can I do that?
@MhM93
as i already said. Don't apply the background-image to the main-window but to the widget you set as central widget... -
Do you mean I set the main window central widget for set back ground image?could you give me example?
So sorry I am beginner in qt(also in English) so sorry :">@MhM93
CSS:QWidget , QDialog { background:rgb(67,67,67); } #MyCentralWidget { background: url(:/myImg/1.jpg); }
CPP:
QFrame* centralWidget = new QFrame; centralWidget->setObjectName("MyCentralWidget"); mainWindow->setCentralWidget( centralWidget );