Results 1 to 3 of 3

Thread: QGraphicsView and adding QWidget with transparent areas

  1. #1
    Join Date
    Apr 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsView and adding QWidget with transparent areas

    Hello,

    I want to use my own Button-Widget in a QGraphicsView. Adding and displaying the widget works fine. Unfortunately this Button has round corners which are not displayed transparent in the view tree. When I use the the same widget in a QMainWindow the outside areas are drawn transparent. The same effect occur by using a default Qt-Widget like QDial.

    This code shows the widget with transparent behavior:
    (I used QTextEdit just to get (quick and dirty) a white background)

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QTextEdit * pEdit = new QTextEdit(&main);
    5. QDial * pDial = new QDial(&main);
    6. pEdit->setGeometry(0,0,main.size().width(),main.size().height());
    7. pDial->setGeometry(40,00,100,100);
    8. main.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    The following code shows the same widget in a QGraphicsView with opaque behavior:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. scene.setBackgroundBrush(Qt::white);
    5. QDial * pDial = new QDial(NULL);
    6. QGraphicsProxyWidget * pWidget = scene.addWidget(pDial,Qt::Widget);
    7. QGraphicsView view(&scene);
    8. view.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Can anyone give me a hint how to render the widget with transparent corners?
    Thanks in advance!

    Denis
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView and adding QWidget with transparent areas

    Why did u set background of scene as white ?

    You should try setting background of scene and view as transparent. And also you can set the top level window flag WA_TranslucentBackground (chk spelling ) .

    There was also some example on Qt Labs where graphics item with transparent background were used... cant remember the link

  3. #3
    Join Date
    Apr 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView and adding QWidget with transparent areas

    hi aamer4yu,

    the hint with the WA_TranslucentBackground flag was all I needed. Setting this flag in the constructor of the derrived widget sets the background to transparent.

    Thank you very much!

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.