Results 1 to 3 of 3

Thread: How to create a Widget that is semi-transparent and on top pf all open Widgets

  1. #1
    Join Date
    Mar 2014
    Posts
    18
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default How to create a Widget that is semi-transparent and on top pf all open Widgets

    Hi all,

    I have an application an want to have something like a semi-transparent Warning-Popup. Everytime the user clicks on a prohibited field, the popup shall come up. My screen has a resolution of 800x480px, but the Popup shall be about 300x400px in the middle of the screen. Everything around the Popup shall be grey and semi-transparent.
    Now I have created a QWidget, that is 800x480px and within this Widget, I have a QFrame with the Warning-information. The QFrame shall not be transparent, but the Widget around must be.

    Can anybody help me to realise that popup?


    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to create a Widget that is semi-transparent and on top pf all open Widgets

    My approach would be this:

    - create a custom widget, let it be full sized
    - in the paintEvent method, fill the whole widget with the transparent color
    - the fill the message area with opaque color
    - then draw the message text into the message area

    Cheers,
    _

  3. #3
    Join Date
    Mar 2014
    Posts
    18
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: How to create a Widget that is semi-transparent and on top pf all open Widgets

    Hi, thanks for your answer.

    I tried to following your hint:

    popup.h:
    Qt Code:
    1. class Popup: public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit Popup(QWidget *parent = 0);
    7. ~Popup();
    8.  
    9. protected:
    10. voi paintEvent(QPaintEvent *){
    11. QPainter p(this);
    12. p.fillRect(rect(),QColor(100,100,100,150));
    13.  
    14. };
    To copy to clipboard, switch view to plain text mode 

    popup.cpp:
    Qt Code:
    1. Popup::Popup(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Popup)
    4. {
    5. ui->setupUi(this);
    6. setAttribute(Qt::WA_TranslucentBackground);
    7. setWindowFlags(Qt::FramelessWindowHint);
    8.  
    9. setStyleSheet("QWidget{background: rgb(100,100,100,150);}");
    10. show();
    11. }
    To copy to clipboard, switch view to plain text mode 

    The problem is, that I have a certain transparency, but it looks as if there would be a black background and my semi-transparent background over it.

    look here. the right picture is without the popup, the left one with the popup:
    IMG_20151208_131951.jpgIMG_20151208_131944.jpg

Similar Threads

  1. Replies: 3
    Last Post: 18th July 2019, 10:25
  2. Semi-transparent widgets on top of QGLWidget
    By GdelP in forum Qt Programming
    Replies: 5
    Last Post: 1st August 2013, 19:06
  3. Semi-Transparent Widgets over OpenGL rendering
    By ddpro in forum Qt Programming
    Replies: 2
    Last Post: 19th August 2010, 01:56
  4. qt4.3 semi-transparent widgets winxp
    By kernel_panic in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2007, 06:25
  5. create QPixmap semi-transparent
    By jamd in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2006, 08:08

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.