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 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
-
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
-
@mrjj thankyou very much the image is now showing however its far too big to pick out all the detail how would I resize ity and shrink it down ?
I plan to use the ui on a 10 inch touchscreen 1280x800
-
@DanJenk
Hi
I would use an image app and scale it down it to the needed res.
(1280x800) and see how that looks. -
@mrjj Thanks again I had resized it in gimp however I forgot to add the new file to resources problemsolved
@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