PDA

View Full Version : A widged surrounded by another used as a Mask



gab74
8th September 2016, 11:39
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

anda_skoa
8th September 2016, 13:03
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,
_

gab74
8th September 2016, 14:13
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 ?

anda_skoa
8th September 2016, 14:54
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,
_

gab74
8th September 2016, 15:00
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..

anda_skoa
8th September 2016, 16:11
Also doable in paintEvent(), QPainter has methods for drawing text, lines, etc.

Cheers,
_

gab74
27th September 2016, 10:04
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

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

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

anda_skoa
27th September 2016, 11:02
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,
_

gab74
27th September 2016, 11:54
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.

anda_skoa
27th September 2016, 12:25
I cannot derive from mapwidget

Why not?



I've subclassed Qframe then reimplemented its paintevent to draw the mask.

Why subclass QFrame? Do you also need a frame inside the map?



Then i will add to Qframe layout the map hoping this will work..

You already did that.
Not what I suggested.



Using the above approach doesent work..

You could try the approach I've suggested.



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

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

Obviously



Is there a way to put the MASK in foreground ??

I would recommend reading comment #8.

Cheers,
_

gab74
27th September 2016, 13:28
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

mapframe->layout->addwidget(MapProprietaryWidget);

MapMask* overlay = new MapMask();
MapMask->setparent(mapframe);

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

anda_skoa
28th September 2016, 12:43
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()



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.



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.



Please i did not find comment #8... where ?

This is comment #12, your last one is comment #11, ...

Cheers,
_