Results 1 to 6 of 6

Thread: [SOLVED] Display order (z-axis) of objects in a same widget

  1. #1
    Join Date
    Mar 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default [SOLVED] Display order (z-axis) of objects in a same widget

    Hey Folks,

    I am new to Qt and i got a problem on an application I am trying to code.
    First of all, i am using Qt5 on Ubuntu.
    That being said, I am trying to code a widget containing a QImage (png) and a label. I would like that at some moment, the image goes on top of the label. A hide() method isn't what I am looking for as my image is not plain and do not recover entirely my label, I still want it to be "part" visible.

    My problem is that my label is always on top and never in background of my QImage, and I don't know how to manage it from my repaint event.

    Here is what my code looks like:
    Qt Code:
    1. QImage myPicture = QImage("./Foo.png");
    2. QPainter painter(this);
    3.  
    4. path.addText(0, 0, painter.font(), "Foo");
    5. painter.drawPath(path);
    6. painter.drawImage(myPicture.rect(), myPicture, myPicture.rect());
    To copy to clipboard, switch view to plain text mode 

    Does anybody have an idea on this problem of mine ?

    Thanks for having a look.
    Last edited by Mystogan; 9th March 2016 at 13:18.

  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: Display order (z-axis) of objects in a same widget

    If you don't use a label but draw the text yourself, you have full control over when you draw which part.

    Alternatively you can use a QGraphicsView and use two sibling items for the image and text and change their Z value accordingly.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Display order (z-axis) of objects in a same widget

    Quote Originally Posted by anda_skoa View Post
    If you don't use a label but draw the text yourself, you have full control over when you draw which part. _
    Can you explain it a bit deeper please ?

    The way my code works, the text is always on top of the QImage, how can I control on the z-level of each element ?

    The QGraphicsView seems to have all the methods to control this z-level, but I was wondering if it was possible to manage it easily the way I coded it initially....

  4. #4
    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: Display order (z-axis) of objects in a same widget

    Quote Originally Posted by Mystogan View Post
    Can you explain it a bit deeper please ?
    Text under image
    Qt Code:
    1. painter.drawText(...);
    2. painter.drawImage(...);
    To copy to clipboard, switch view to plain text mode 
    Text over image
    Qt Code:
    1. painter.drawImage(...);
    2. painter.drawText(...);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Mar 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Display order (z-axis) of objects in a same widget

    Nice, it works well with the drawText method !! Thank you !

    However do you know why it wouldn't work using the path.addText/drawPath methods ?

    Thanks again for your help.

  6. #6
    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: Display order (z-axis) of objects in a same widget

    You mean using drawPath() after drawImage()? That should work as well.

    Chrers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 28th October 2016, 11:12
  2. Display System Drives in Specific Order in QTreeView
    By owais_blore in forum Qt Programming
    Replies: 6
    Last Post: 5th December 2012, 08:07
  3. Using a tree widget to display a list of model objects
    By xtal256 in forum Qt Programming
    Replies: 9
    Last Post: 30th May 2011, 03:00
  4. Changing QTableView column display order
    By scarleton in forum Qt Programming
    Replies: 3
    Last Post: 18th October 2010, 00:04
  5. display order of subwindows in mdi area
    By eric_vi in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2010, 16:05

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.