Diskplaying a background image in main window.
-
Hi nguys
Very new to all this qt and programming but I am starting to learn slowly.
I have an issue setting a .jpg picture as the back ground in the main window on qt creator , here is the code
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
setStyleSheet("MainWindow {background-image:url(c:/Users/danny/Downloads/Tank-Konbackground.jpg)}");}
MainWindow::~MainWindow()
{
delete ui;
}I have already used Qpixmap and had the background working however I could not add text or wodgets over the top.
After some more reading I came across the above example but when I run the code no image appears
Can anybody help me out
Danny
-
Hi
You can using a resource file instead of direct path.
Works much better later on other pc :)Add the res file
Add the image
Take the path
use res path in stylesheet
-
@DanJenk
keep in mind, when you modify your resource files, (e.g adding a new picture or editing an existing one)make sure to make a clean rebuild of your project, clean -> run qmake -> build, otherwise the changes my not be applied/ files not found