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. Use an image as background of QFrame without using Qt::WA_TranslucentBackground
Forum Update on Monday, May 27th 2025

Use an image as background of QFrame without using Qt::WA_TranslucentBackground

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 1.2k Views
  • 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.
  • C Offline
    C Offline
    Cupidvogel
    wrote on 17 Dec 2015, 21:15 last edited by
    #1

    I am making a desktop carousel app. There I need to show image widgets, which might contain other sub-widgets as well. For that I am using a QFrame with the required image as background. Here is the image I am trying to use: http://imgur.com/RnSghvV. What I want is that only the image shows up, no background image or anything shows up as well, so to the user it looks like just the image. Here is my code:

    main.h

    #ifndef main_h
    #define main_h
     
    #include <QFrame>
    #include <QPixmap>
     
    class MyFrame : public QFrame
    {
    public:
       MyFrame(QWidget * parent);
     
       virtual void paintEvent(QPaintEvent * e);
     
    private:
       QPixmap _pixmap;
    };
     
    #endif
    

    main.cpp

    #include <QApplication>
    #include <QPainter>
    #include "main.h"
     
    MyFrame :: MyFrame(QWidget * parent) : QFrame(parent, Qt::Window|Qt::FramelessWindowHint)
    {
       setAttribute(Qt::WA_TranslucentBackground);
     
       _pixmap.load("/Users/jaf/iPad_Vector.png");
       resize(_pixmap.size());
    }
     
    void MyFrame :: paintEvent(QPaintEvent * /*e*/)
    {
       QPainter p(this);
       p.drawPixmap(0,0,width(),height(), _pixmap);
    }
     
    int main(int argc, char ** argv)
    {
       QApplication app(argc, argv);
     
       MyFrame f(NULL);
       f.show();
     
       return app.exec();
    }
    

    This works fine as expected, the image appears correctly like here: http://i.stack.imgur.com/yJXHU.png.

    But in my use-case, I need to display an image (as QWidget with the image as background, again!) that is rendered via GL inside the QFrame (specifically, in the viewport within the iPad image we can see here). In Windows, setting the Qt::WA_TranslucentBackground property makes that GL-rendered image invisible. It works fine in Mac, though. So I am looking for a solution which will work in Windows as well. How can I make it behave in the same way without using Qt::WA_TranslucentBackground?

    1 Reply Last reply
    0

    1/1

    17 Dec 2015, 21:15

    • Login

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