Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Help showing an image as a background
Forum Updated to NodeBB v4.3 + New Features

Help showing an image as a background

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rulovic
    wrote on last edited by
    #1

    Hi all:
    I am getting started in Qt world.
    Im coding an application and I want to show a screen with background and later start adding widgets on it
    This is what I have so far:

    @
    //widget and background intialization
    QWidget *widget = new QWidget;
    widget->setStyleSheet("background-image: url(Tapete.png)");
    //widget->setGeometry(QRect(100,100,128,128));
    QHBoxLayout *layout = new QHBoxLayout;
    QPushButton *button = new QPushButton("Button");
    layout->addWidget(button);
    bck->setLayout(layout);
    addWidget(bck);
    @

    and main method:

    @
    QApplication app(argc, argv);
    QGraphicsView *view = new QGraphicsView;
    Window *v = new Window;
    view->setScene(v);
    view->show();
    return app.exec();
    @

    but for some reason I cannot get the image displayed on the screen
    Can you help me please??
    Thanks a lot in advance!!!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      ShadowMoses
      wrote on last edited by
      #2

      http://stackoverflow.com/questions/4458201/unable-to-set-the-background-image-in-qt-stylesheet

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leon.anavi
        wrote on last edited by
        #3

        Make sure that file Tapete.png exists on the correct location.

        http://anavi.org/

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rulovic
          wrote on last edited by
          #4

          Hi:
          Thanks both it was a problem with paths, once I added the file to resources it worked fine :)
          But now I've come accross with another two problems.
          As you can see on the picture
          !http://img23.imageshack.us/img23/1511/imageyhj.jpg/(image)!
          there is a white frame surrounding the background? how can expand the image to use all the available window?
          On the other hand I've added a button but it is taking same background and i don't want it. How can solve it.
          I've tried creating a custom class which inherits QWidget but result is the same

          1 Reply Last reply
          0
          • L Offline
            L Offline
            leon.anavi
            wrote on last edited by
            #5

            [quote author="rulovic" date="1323040204"]
            there is a white frame surrounding the background? how can expand the image to use all the available window?[/quote]

            Have you set the "background-repeat":http://doc.qt.nokia.com/stable/stylesheet-reference.html#repeat property?

            http://anavi.org/

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rulovic
              wrote on last edited by
              #6

              yes. I used:

              @setStyleSheet("background-image: url(:/images/tapete.png);background-origin: content;background-clip: margin;");@

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stemd
                wrote on last edited by
                #7

                Somehow in above line I miss keyword @repeat@

                You forgot to write it here, or you forgot to write it in your program?

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rulovic
                  wrote on last edited by
                  #8

                  I forgot to write it here, I have it in my program but the result is the same :s

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved