Results 1 to 6 of 6

Thread: QLabel on top of a QGLWidget background issue

  1. #1
    Join Date
    Jan 2006
    Location
    Third rock from the sun
    Posts
    106
    Thanks
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QLabel on top of a QGLWidget background issue

    I am attempting to make a radial menu expander in a corner of an QGLWidget scene by subclassing a QLabel, adding a pixmap, adding mousePressEvent and mouseReleaseEvent overrides and move(ing) the label to the corner of the widget (i.e. not adding into a layout). I do not want to add in as an object in my GL scene since the popup menus that will appear need to be generic and very user definable.

    Qt Code:
    1. QPixmap pix( ":/files/add_button" );
    2. QLabel *menuWidget = new QLabel( glWidget );
    3. menuWidget->setAutoFillBackground( false ); // Should not be needed
    4. menuWidget->setPixmap( pix );
    5.  
    6. menuWidget->move( 100, 100 );
    To copy to clipboard, switch view to plain text mode 

    The add_button pixmap is a PNG with a transparent background.

    The image displays in the proper place, but the background color of the image is black (incidently the same color as the qglClearColor) instead of clear. Secondly, when I click on the image and replace with a larger image, I can see the image change, but its size does not.

    Any thoughts? Sorry no code to post, on a different system.
    Every little child knows
    if you cant see dreams
    your eyes are blind

    Moxy Fruvous

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QLabel on top of a QGLWidget background issue

    The image displays in the proper place, but the background color of the image is black (incidently the same color as the qglClearColor) instead of clear.
    That is because the GL content is not in Qt context, so Qt does not know about it anything, which means, you QLabel can't know which background it should fill - so its black.
    Secondly, when I click on the image and replace with a larger image, I can see the image change, but its size does not.
    You have to resize the QLabel to flt your image.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    Third rock from the sun
    Posts
    106
    Thanks
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel on top of a QGLWidget background issue

    Quote Originally Posted by high_flyer View Post
    That is because the GL content is not in Qt context, so Qt does not know about it anything, which means, you QLabel can't know which background it should fill - so its black.
    Is there anyway to switch the QLabels context to GLs?
    Every little child knows
    if you cant see dreams
    your eyes are blind

    Moxy Fruvous

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel on top of a QGLWidget background issue

    You could use a graphicsscene with a glwidget as viewport. Put your GL calls in the scenes.drawBackground and put your code inbetween painter.beginNativePainting() and painter.endNativePainting().. Add your pixmap as a qgraphicspixmapitem.

    Or you draw the pixmap directly to your glwidget instead of using a label. Use QPainter::drawPixmap .. http://doc.qt.nokia.com/latest/qglwi...ing-techniques

    HIH

    Johannes

  5. #5
    Join Date
    Jan 2006
    Location
    Third rock from the sun
    Posts
    106
    Thanks
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel on top of a QGLWidget background issue

    Quote Originally Posted by JohannesMunk View Post
    You could use a graphicsscene with a glwidget as viewport. Put your GL calls in the scenes.drawBackground and put your code inbetween painter.beginNativePainting() and painter.endNativePainting().. Add your pixmap as a qgraphicspixmapitem.

    Or you draw the pixmap directly to your glwidget instead of using a label. Use QPainter::drawPixmap .. http://doc.qt.nokia.com/latest/qglwi...ing-techniques
    I am trying to keep it out of the GL widget if possible for reuseability, but if I cannot I will probably go the QGraphicsView route. Is there any benefit to putting the GL calls in drawBackground vs. paintEvent in QGraphicsView?
    Every little child knows
    if you cant see dreams
    your eyes are blind

    Moxy Fruvous

  6. #6
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel on top of a QGLWidget background issue

    As the view is conceptually only the display of the scene which contains the content, you would break that concept, if you put content into the view.

    As you want your item to be on top of your other gl stuff, I though the background would be appropriate for it.

    Joh

Similar Threads

  1. Replies: 1
    Last Post: 7th May 2010, 17:20
  2. Replies: 0
    Last Post: 8th April 2010, 16:06
  3. QgraphicsScene on QGLWidget background
    By ksrini in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2009, 09:57
  4. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36
  5. (qt4 & xp) qlabel as background in designer
    By incapacitant in forum Newbie
    Replies: 5
    Last Post: 5th March 2006, 11:21

Tags for this Thread

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.