[Qt-interest] QDialog with background image

David Boosalis david.boosalis at gmail.com
Thu Jul 30 16:24:38 CEST 2009


Don't know about style sheets but you could just implement your own
resizeEvent and paintEvent().  For example:

class Dialog : public QDialog {
public:
  Dialog(QWidget *parent=0):QDialog(parent) {
    QGridLayout *grid = new QGridLayout();
    setLayout(grid);
    QPushButton *startB = new QPushButton("Start Me", this);
    grid->addWidget(startB,0,0,Qt::AlignCenter);
    pixmap = QPixmap("mybackground.png");
  }
protected:
  void resizeEvent(QResizeEvent *re) {
    pixmap  = pixmap.scaled(re->size(),Qt::KeepAspectRatioByExpanding);
  }
  void paintEvent(QPaintEvent *re) {
    QPainter painter(this);
    painter.drawPixmap(0,0,pixmap);
  }
private:
  QPixmap pixmap;
};

int main(int argc, char *argv[])
{
  QApplication app(argc,argv);
  Dialog *dialog = new Dialog();
  dialog->show();
  app.exec();

}

On Thu, Jul 30, 2009 at 4:23 AM, Paresh Sawant <paresh.sawant at gmail.com>wrote:

> Hi,
>
> I am creating a dialog application with QDialog on windows mobile device
> (windows mobile professional 6.1)
>
> I want to set a background image using style sheet, so I am using
> "background-image: url(xyz.png)".
>
> The dimension of this image file is 290 X 240.
>
> When I run the dialog application, i change the dialog size using resize(),
> to make it look proportionate on the bigger screen geometry, which is around
> 450 X 550.
>
> But since the dimension of the image is smaller it gets repeated over the
> dialog area, instead of getting stretched.
>
> How could I use the same image file for different screen sizes ?
>
> - Paresh
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090730/5cb85f6f/attachment.html 


More information about the Qt-interest-old mailing list