Results 1 to 2 of 2

Thread: Need to display a QFrame with only background image and nothing else

  1. #1
    Join Date
    May 2014
    Posts
    136
    Thanks
    72
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    MacOS X Windows

    Default Need to display a QFrame with only background image and nothing else

    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://static.vecteezy.com/system/re...Pad_Vector.png. 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:

    Qt Code:
    1. setGeometry(QRect(100, 20, 325,400));
    2. setFrameStyle(QFrame::StyledPanel);
    3. setStyleSheet("QFrame#ImageFrame { background-color: transparent; background: url(:icon/ipad-skin); }");
    4. setAutoFillBackground(false);
    To copy to clipboard, switch view to plain text mode 

    However, I ma getting this as a result:

    Screen Shot 2015-06-02 at 1.25.01 PM.jpg

    How do I make the grey background of the QFrame go and display only the image?

  2. #2
    Join Date
    May 2014
    Posts
    136
    Thanks
    72
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    MacOS X Windows

    Default Re: Need to display a QFrame with only background image and nothing else

    I managed to find a working solution -

    main.h:

    Qt Code:
    1. #ifndef main_h
    2. #define main_h
    3.  
    4. #include <QFrame>
    5. #include <QPixmap>
    6.  
    7. class MyFrame : public QFrame
    8. {
    9. public:
    10. MyFrame(QWidget * parent);
    11.  
    12. virtual void paintEvent(QPaintEvent * e);
    13.  
    14. private:
    15. QPixmap _pixmap;
    16. };
    17.  
    18. #endif
    To copy to clipboard, switch view to plain text mode 

    main.cpp

    Qt Code:
    1. #include <QApplication>
    2. #include <QPainter>
    3. #include "main.h"
    4.  
    5. MyFrame :: MyFrame(QWidget * parent) : QFrame(parent, Qt::Window|Qt::FramelessWindowHint)
    6. {
    7. setAttribute(Qt::WA_TranslucentBackground);
    8.  
    9. _pixmap.load("/Users/jaf/iPad_Vector.png");
    10. resize(_pixmap.size());
    11. }
    12.  
    13. void MyFrame :: paintEvent(QPaintEvent * /*e*/)
    14. {
    15. QPainter p(this);
    16. p.drawPixmap(0,0,width(),height(), _pixmap);
    17. }
    18.  
    19. int main(int argc, char ** argv)
    20. {
    21. QApplication app(argc, argv);
    22.  
    23. MyFrame f(NULL);
    24. f.show();
    25.  
    26. return app.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

    This works. However, in my use case, I need to display an image 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. How can I make it behave in the same way without using Qt::WA_TranslucentBackground?

Similar Threads

  1. Replies: 4
    Last Post: 27th November 2013, 15:15
  2. Replies: 3
    Last Post: 3rd August 2012, 10:35
  3. Replies: 0
    Last Post: 5th April 2011, 13:36
  4. Setting background image of QFrame
    By Claymore in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2007, 19:50
  5. QFrame and its background
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2006, 20:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.