Results 1 to 14 of 14

Thread: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    Hi everybody !

    I have an application (SDI) and I must update its HMI. This application displayes some 3D stuffs and I need to display some pictures in front of it.

    I want to developp a custom widget that could be drawn wherever I want, with the transparency and the rotation I specified. Thoses pictures could be resized.

    I am not sure the base class I must use. I am sure the application doesn't use QCanvas so I will probably use QWidget or QGLWidget as a base class, but as I am newbe to OpenGL I prefer using QWidget instead of QGLWidget.

    What I want to know is :
    * do QWidget and QGLWidget can answer to my needs ?
    * which solution offers me best performances (draw speed, maintenance, ...) ?
    * will it be difficult to answer to my need using OpenGL (I don't know this technology) ?
    * is it possible to use QCanvasItem even if the application does not use QCanvas technology (it is a very big application I can't update totally and straightforwardly) ?

    If someone could help me to choose the way to developp my widget.

    Thanks in advance.
    Last edited by yellowmat; 31st October 2006 at 17:19. Reason: Title more accurate

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    You only want pictures? Why don't you use QLabel with transparent pixmaps then?

  3. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    My custom is not a single picture object, it could contain many pictures over it.

    This custom widget is a map with map informations (displayed as pictures) drawn uppon it. I must be able to control the opacity of each pictures uppon the map but also of the map drawn uppon the main window. For the moment I just need to display the map with the camera perpendicular to it, but maybe I will have to display the map in a different view or use the pixmap as a texture on a specific 3D shape.

    If transparents pixmaps used with QLabel could give me full control over opacity, you are right, I should use it but even if it could answer the opacity need, I don't think it will answer the view need (texture).

    I have study OpenGL this week end, it should not be too difficult to implement a map using this technology and QGLWidget.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    I don't think you can benefit from QGLWidget in any way (maybe just speed). The easiest solution would be to have a QLabel and display a pixmap which would be composed of all the pictures you want to display (I just don't know if Qt3 can handle that). I think using QCanvasItem is not an option here unless you already use the canvas to display your map.
    To be honest, if you switched to Qt4, your life would become easier as Qt4 fully supports blending and transparency. If you stick to Qt3, you may be forced to do some wacky things to compose all the pixmaps (like having top-level windows with opacity changed and moving those windows over your map).

  5. #5
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    I can't switch to QT4 despite I know everything will be easier.

    I agree with you about QCanvas. As the application does not use canvas it would be too hard and too long to update it in order to use canvas.

    I don't understand why you tell me that I won't be able to benefit from QGLWidget in any way ? It is totally possible to draw and manage many objects with opacity control. The main problem could be the implementation of such a solution but it does not require to be an openGl master (I said I don't know this technology but in fact I know how to create objects, map textures on objects).

    As I have not choosen the implementation solution yet, could you tell me some more about the difficulties / disadvantages of using QGLWidget ?

    Thanks in advance

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    Quote Originally Posted by yellowmat View Post
    I don't understand why you tell me that I won't be able to benefit from QGLWidget in any way ? It is totally possible to draw and manage many objects with opacity control. The main problem could be the implementation of such a solution but it does not require to be an openGl master (I said I don't know this technology but in fact I know how to create objects, map textures on objects).

    As I have not choosen the implementation solution yet, could you tell me some more about the difficulties / disadvantages of using QGLWidget ?
    Maybe I was a bit unclear I meant that I don't think that using QGLWidget will give you any advantages over other solutions (especially over using compositions with Qt4). The main problem I see is to provide opacity for the resulting GL image. OpenGL will let you compose (blend) objects but will not provide you with a transparent background - you'll have to either move displaying your map into the GL context or find a way to make the GL background transparent without loosing desired transparencies of the pictures you have placed in the GL widget. AFAIR Qt3 will only let you make the whole widget transparent in the same degree - you won't be able to make some parts more and some less transparent. Of course all my remarks apply only if I understood correctly what you want to do.

  7. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    > I can't switch to QT4 despite I know everything will be easier.

    Many things are easier, but performance and stability are better with Qt3. Also direct painting to a QWidget is only supported by Qt3, what is important for incremental painting or implementing interactions.

    There are good reasons to use Qt4, but there are also many good reasons not to do so. Better make your own decision !

    > tunable opacity

    You might have a look at Qwt (http://qwt.sf.net).

    Qwt offers a class, that is called QwtPlotRasterItem, that renders a QImage. With QwtPlotRasterItem::setAlpha you can change its opacity.

    Look at the implementation of QwtPlotRasterItem to see how alpha blending of images can be done with Qt3 (or Qt4, both is supported by Qwt). If you render your images from raster data, you might also have a look at QwtPlotSpectrogram.

    I used Qwt myself in a type of GIS applications, where maps and raster data (like elevation, population ...) need to be rendered in layers with tunable opacity. Don't know if you requirements are similar, but maybe using QwtPlot instead of QCanvas is an option for you too.

    HTH,
    Uwe

  8. #8
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    Uwe, to be clear, I could be great to switch from QT3 to QT4 ... but it is not my choice, it is my boss's

    I am unable to open your link, have you tried it soon ?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    Quote Originally Posted by yellowmat View Post
    I am unable to open your link, have you tried it soon ?
    Just remove ")", which was appended to the link by accident: http://qwt.sf.net

  10. #10
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    Pfff, sorry not to have seen that. Just the beginning of the week and already tired

  11. #11
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    Wysota, you are right and understood the problem.

    In fact (I can say that now because I have learned a little bit opengl those days), OpenGl just can let me construct an image composed of many others, with blended colors and alpha factors but does not make the widget background transparent. I thought it was possible using a clear color with alpha factor set to full transparent, , my problem is not solved yet.

    In the same time I made the following test :
    * create a SDI application
    * create a custom widget dispalying a single image and initialize it with its parent
    * apply to this widget the setWindowOpacity with something inferior to 1.0 and superior to 0.0

    As result, my widget should have been transparent and it should have been possible to see the application background through the widget ... in fact the result was not the expected one because the widget was not transparent. Isn't it possible to apply the setWindowOpacity to a custom widget ? It works pretty well when I apply it to the main window object ? Must I do something special to have my widget background transparent ?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    I don't know what you exactly did, but setWindowOpacity works only for top-level windows.
    Maybe you could try what Uwe suggested?

  13. #13
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    Hi,

    I have the following requirement,
    Support multiple layers in a Qt desktop application with ability to control the opacity of each layer.
    Display raster map(Dted level 0 elevation data).

    previous replies in the post says,
    1. "Qwt offers a class, that is called QwtPlotRasterItem, that renders a QImage."
    Does it actually render any raster format supported by GDAL? As i have built Qwt and found that it doesnt use GDAL libraries.

    2. "I used Qwt myself in a type of GIS applications, where maps and raster data (like elevation, population ...) need to be rendered in layers with tunable opacity."
    My requirements is very similar, can you suggest me how to proceed further?
    Possibly sharing the code that displays elevation data on a normal Qt widget

    Looking forward to your response

  14. #14
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Graphic object with tunable opacity ... QWidget, QGLWidget or QCanvasItem ?

    Quote Originally Posted by csvivek View Post
    Does it actually render any raster format supported by GDAL? As i have built Qwt and found that it doesnt use GDAL libraries.
    Qwt doesn't implement any type of file format. It gets the data through an abstract API called QwtRasterData.
    It's the job of the application to implement this API by deriving from QwtRasterData.

    1) initRaster()

    Load + resample your data for a specific area and resolution

    2) discardRaster()

    Called after the image is rendered. You can do cleanups here.

    3) range()

    The interval that corresponds to your color map ( not the min/max values of your raster data). F.e. for elevation this might be something like 0-5000.

    4) value(double x, double y)

    A value for a specific position.

    Uwe

    PS: Please don't use different threads for one topic.

Similar Threads

  1. Transparent QWidget on QGLWidget
    By showhand in forum Qt Programming
    Replies: 2
    Last Post: 27th November 2006, 01:00

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
  •  
Qt is a trademark of The Qt Company.