Results 1 to 12 of 12

Thread: A widged surrounded by another used as a Mask

  1. #1
    Join Date
    Sep 2011
    Posts
    51
    Qt products
    Qt4
    Thanks
    2

    Default A widged surrounded by another used as a Mask

    Good morning,
    i've to develop a map software.
    The map is in a qwidget and all is ok.
    I've to surround the map with a circle angle degree used as mask in which I've to insert some other widget.
    So i need to know how can i insert a circle png over a widget, but i must click the above layer.

    See the picture:
    I've the png picture as the blue mask with transparent hole, the big angle degree cicrle
    I can click the underground map.

    Anyone can help me in showing an example how can i develop a widget sourrounded by another ?
    See the picture attached
    I must use qt 4.2
    Attached Images Attached Images

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

    Default Re: A widged surrounded by another used as a Mask

    Sounds to me more like a use case for a single widget.

    First it draws the inner part, then the "hole" image on top.
    Or even just using a QPainterPath to draw the hole.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2011
    Posts
    51
    Qt products
    Qt4
    Thanks
    2

    Default Re: A widged surrounded by another used as a Mask

    So :
    i have the widget thats draws the map, this widget is connected to a map server that generate the map.
    If i click on map i can zoom pan ecc ecc like any map programs...
    I do not understand how can i draw the hole and the blue borders over this widget.
    Con you be more specific ?
    Consider that in the blue part i've to insert check boxes and button to manage the map...
    Please can you write me a little pseudo-code ?

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

    Default Re: A widged surrounded by another used as a Mask

    I would draw the blue part in the same widget as the map, i.e. in that widget's paintEvent() method.

    Buttons and other widgets can then easily be placed on top, i.e. as children of the map widget.

    Cheers,
    _

  5. #5
    Join Date
    Sep 2011
    Posts
    51
    Qt products
    Qt4
    Thanks
    2

    Default Re: A widged surrounded by another used as a Mask

    Ok Thank you very much.
    Last question.
    As you can see there are numbers and lines in the circle to represent Degree.
    How can i solve this last problem ?
    I think using a trasparent png is a wrong approach..

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

    Default Re: A widged surrounded by another used as a Mask

    Also doable in paintEvent(), QPainter has methods for drawing text, lines, etc.

    Cheers,
    _

  7. #7
    Join Date
    Sep 2011
    Posts
    51
    Qt products
    Qt4
    Thanks
    2

    Default Re: A widged surrounded by another used as a Mask

    Sorry i cannot yed solved my problem.
    I have a QMainWindow with a QFrame
    in QFrame i have a proprietary qtWidget that draws the map.
    i added this proprietary widget to Qframe with
    Qt Code:
    1. mapFrame->layout()->addwidget(MyProprietaryWidget)
    To copy to clipboard, switch view to plain text mode 
    And all works well i see the map inside the QFrame.
    Now i need to add the circle mask.. to mask some map area as the image attached in thread.
    I think i've to sublcass paintevent of QFrame and not of MainWindow to draw the shapes :
    So
    1) How can i override only QFrame method to add a shape over ?
    Can you explain me with meta code ??? or a simple example ?
    I think after adding the proprietary widget i can draw shapes to mask some map area.
    Thank you

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

    Default Re: A widged surrounded by another used as a Mask

    My suggestion would be to

    1) derive from that map widget,
    2) overwrite paintEvent()
    2a) call the base class paintEvent to draw the map
    2b) draw the mask on top

    I think your other options is to
    1) derive a new class from QWidget
    2) implement paintEvent() to draw the mask
    3) add a layout to the map widget, with spacing set to 0
    4) add an instance of your widget to the layout

    Cheers,
    _

  9. #9
    Join Date
    Sep 2011
    Posts
    51
    Qt products
    Qt4
    Thanks
    2

    Default Re: A widged surrounded by another used as a Mask

    Quote Originally Posted by anda_skoa View Post
    My suggestion would be to

    1) derive from that map widget,
    2) overwrite paintEvent()
    2a) call the base class paintEvent to draw the map
    2b) draw the mask on top

    I think your other options is to
    1) derive a new class from QWidget
    2) implement paintEvent() to draw the mask
    3) add a layout to the map widget, with spacing set to 0
    4) add an instance of your widget to the layout

    Cheers,
    _

    I cannot derive from mapwidget so i will try to follow second options.
    I've subclassed Qframe then reimplemented its paintevent to draw the mask.
    Then i will add to Qframe layout the map hoping this will work..
    I will let you know.
    Thankyou in advance


    Added after 15 minutes:


    Using the above approach doesent work..

    I see that the MASK added in paintevent method is hidden by the mapProprietaryWidget when i set

    mapFrame->layout()->addwidget(MyProprietaryWidget)

    So it works if i do not add the MyProprietaryWidget and i see the MASK, but if i add the MyProprietaryWidget the mask remains in background.
    Is there a way to put the MASK in foreground ??

    Thankyou

    mapFrame is a QFrame subclassed with paintevent reimplemented to draw the mask.
    Last edited by gab74; 27th September 2016 at 12:54.

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

    Default Re: A widged surrounded by another used as a Mask

    Quote Originally Posted by gab74 View Post
    I cannot derive from mapwidget
    Why not?

    Quote Originally Posted by gab74 View Post
    I've subclassed Qframe then reimplemented its paintevent to draw the mask.
    Why subclass QFrame? Do you also need a frame inside the map?

    Quote Originally Posted by gab74 View Post
    Then i will add to Qframe layout the map hoping this will work..
    You already did that.
    Not what I suggested.

    Quote Originally Posted by gab74 View Post
    Using the above approach doesent work..
    You could try the approach I've suggested.

    Quote Originally Posted by gab74 View Post
    I see that the MASK added in paintevent method is hidden by the mapProprietaryWidget when i set

    mapFrame->layout()->addwidget(MyProprietaryWidget)
    Obviously

    Quote Originally Posted by gab74 View Post
    Is there a way to put the MASK in foreground ??
    I would recommend reading comment #8.

    Cheers,
    _

  11. #11
    Join Date
    Sep 2011
    Posts
    51
    Qt products
    Qt4
    Thanks
    2

    Default Re: A widged surrounded by another used as a Mask

    Ok i try to explain.. because i do not understand...sorry for my english...
    This project has a MainWindow.
    Inside the mainWindow i have a QFrame.
    In this QFrame i added MapProprietaryWidget, this widget is from a simualtion engine, so i dont' know if it is possible to draw inside this layer, and i don't know how to reimplement qpaintevent for this widget...
    This special widget is from MAK Simulators it is a DtBaseWindow... something like a QtBaseWindow..i think..
    I know QT not the Framework from which this widget came... and i do not know how to add a layout to this widget..
    So I try the solution to draw the MASK inside the QFrame, (so i've reimplent paintevent of QFrame subclassing..."using promote to" and this works..)
    Please i did not find comment #8... where ?
    Thank you very much for your precious support...

    In other words problem will be :
    I've a QFrame, I added a widget to this QFrame and finally i need to put overall a ShapeMask

    At the moment i've create a simple widget sublcassing qwidget, then implement qpaintevent in which i insert the shape.
    then
    Qt Code:
    1. mapframe->layout->addwidget(MapProprietaryWidget);
    2.  
    3. MapMask* overlay = new MapMask();
    4. MapMask->setparent(mapframe);
    To copy to clipboard, switch view to plain text mode 

    So i see the shape over the map but i cannot click on the map at all to make zoom pan hook...at all... clicking inside the hole... so problem still remains...no solution still found...

    Adding this to
    Last edited by gab74; 27th September 2016 at 16:52.

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

    Default Re: A widged surrounded by another used as a Mask

    Quote Originally Posted by gab74 View Post
    In this QFrame i added MapProprietaryWidget, this widget is from a simualtion engine, so i dont' know if it is possible to draw inside this layer, and i don't know how to reimplement qpaintevent for this widget...
    Like for any other widget:
    - derive from it
    - overwrite paintEvent()

    Quote Originally Posted by gab74 View Post
    I know QT not the Framework from which this widget came... and i do not know how to add a layout to this widget..
    Like for any other widget. either
    - pass the widget to a layout's constructor
    - call the widget's setLayout() method.

    Quote Originally Posted by gab74 View Post
    So I try the solution to draw the MASK inside the QFrame, (so i've reimplent paintevent of QFrame subclassing..."using promote to" and this works..)
    Not sure what you need the additional from for, but ok.

    Quote Originally Posted by gab74 View Post
    Please i did not find comment #8... where ?
    This is comment #12, your last one is comment #11, ...

    Cheers,
    _

Similar Threads

  1. Dialog Mask
    By thahir1986 in forum Newbie
    Replies: 6
    Last Post: 26th October 2010, 08:06
  2. QLineedit mask
    By sudhansu in forum Qt Programming
    Replies: 11
    Last Post: 12th March 2010, 13:10
  3. Qt 4 expanded mask
    By bunjee in forum Qt Programming
    Replies: 4
    Last Post: 7th May 2008, 15:21
  4. help with.. numeric mask....
    By ocascante in forum Qt Tools
    Replies: 1
    Last Post: 12th July 2007, 10:53
  5. MainWindow mask
    By SirBabyface in forum Qt Programming
    Replies: 0
    Last Post: 11th July 2007, 16:12

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.