GraphicsView -> Problem when maximizing window



  • Hi, I am a newbie. I have set graphicsview(with a background image) as my central widget. When I Maximize my window , the background image in the graphics view keeps repeating and doesn't get maximized. I have tried almost all of the formatting options in the mainWindow.ui form editor.

    My objective is to have a background picture in my window and it should maximize along with the window (when the window is maximized) .

    Any sample code or guidance will be helpful.

    Thanks in Advance .



  • post your code so we can see what you are doing wrong



  • Hi ,
    The following code is in my mainwindow.cpp file.
    I have just included a background-image to my graphicsview. When I build and run my project, the image in the graphicsview takes its own resolution, i.e., it doesn't fit exactly into my graphicsview. And when I maximize my mainwindow to fit the entire screen, the image in the graphicsview repeats ( my screen resolution is larger than the image resolution) .
    I am sure I am yet to learn some basic stuff but I just cant figure out what it is.

    <mainwindow.cpp>

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    this->setCentralWidget(ui->graphicsView);
    ui->graphicsView->setStyleSheet("background-image: url(:/my/coffee-cup-01.jpg)");
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }



  • Try using border image

    @ui->graphicsView->setStyleSheet("border-image: url(:/my/coffee-cup-01.jpg)”);@



  • Try using border image

    @ui->graphicsView->setStyleSheet("border-image: url(:/my/coffee-cup-01.jpg)”);@



  • Thanks KIIIGablo , it worked !! :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.