How to specify symbol position on the marker? - qt

I am using Qwt library. I have added vertical QwtPlotMarker on the plot. I want to add QwtSymbol to my marker and I want the symbol to be in the bottom of the marker. When I use setSymbol() it places symbol in the middle of the marker. There are setLabelAlignment() function to specify where the label is drawn. Unfortunately, I did not found anything like that for symbol. I have read Qwt User's Guide where I found: The setSymbol() member assigns a symbol to the marker. The symbol is drawn at the specified point. So, how to specify that point?

It is a very old question, but I found solution and I want to share with you.
There is way to specify this point. Method setValue(double x, double y) do this, but this method not describes in the documentation (it's very strange for me), but this method works!
I wrote small but useful snippet. If I understand you correctly, this code do exactly what you need
QwtSymbol *sym=new QwtSymbol(QwtSymbol::Diamond,QBrush(Qt::red),QPen(Qt::red),QSize(5,5));
//create the symbol
QwtPlotMarker *mark=new QwtPlotMarker;
mark->setSymbol(sym);
mark->setLineStyle(QwtPlotMarker::VLine);
//set vertical line
mark->setValue(5,ui->qwtPlot->axisInterval(QwtPlot::yLeft).minValue());
//here you have to set the coordinate axis i.e. where the axis are meeting.
//as you can see I set coordinate 5 and the lowest coordinate of Y axis
//you can set here needed coordinates
mark->attach(ui->qwtPlot);
I hope, it helps.

Related

Coloring the reverse side of mesh tiles in Scilab

In plot3d2 and similar graphic functions of Scilab, is there a way to set the colour of the back (reverse, flip, inner) side of facets?
I'm trying to draw a part of a (rather crude) torus, and the result is OK except for one row of facets. I suppose that, because of the way I generate the mesh, those facets are oriented differently - whatever algorithm renders them on the screen follows their perimeter in the opposite direction compared to others.
Instead of poring over my code to try to mend the topology of my mesh, I'd rather make sure the facet orientation doesn't matter - just set both sides to my colour. It will also improve the looks of the ends of my torus, where the inside shows and, again, is in a colour I didn't ask for.
But, hard as I search the documentation, I cannot find any mention of the flip side of mesh facets.
Any clues?
The backface color is named "hiddencolor" in the properties of a surface entity (see https://help.scilab.org/docs/6.1.1/en_US/surface_properties.html). It can be changed a posteriori, for example:
[X,Y]=meshgrid(-1:0.5:1);
plot3d2(X,Y,X.^2-2*Y.^2)
gce().hiddencolor=color("red")
You can assign -1 (instead of above) to use the same color as the front facing patches.
However, if all your patches are facing wrongly, you can also transpose all your matrices in the plot3d2 call:
[X,Y]=meshgrid(-1:0.5:1);
plot3d2(X',Y',(X.^2-2*Y.^2)')
gce().hiddencolor=color("red")

Setting the orientation of gameobjects works?

I'm trying to change the orientation of a gameobject by updating the table gameobject with the columns rotation0, rotation1, rotation2, rotation3.
So far the only thing that I got was the despawning of the item if the value was greater than 1. Changing it seems to not have an effect, and I don't know if the implementation works or if I'm missing something.
On the wiki there is not a single explanation as which rotation modifies X Y or Z axis too.

Crop image in scilab

I want to crop image using mouse selection at particular region of interest in scilab,here my code is
I=imread('G:\SCI\FRAME\mixer2.jpg');
I1G = rgb2gray(I);
figure();ShowImage(I1G,'mixer');
IN1G = gca();
rect1 = rubberbox();
ROI1=imcrop(I1G,rect1);disp(ROI1);
But it gives the following error: The rectangle is out of the image range.
and i also use xclick and xgetmouse function for cropping using mouse selection and it also gives the same error.
please give me suggestions for correcting code .
Thanks and Regards
The problem arises from the difference between the image coordinate system (used by imcrop and all the other functions of the SIVP toolbox) and the "regular" coordinate system (used by rubberbox, xcick and all the builtin functions). Images have the first pixel at top-left. On the contrary rubberbox have the zero at bottom left.
To correct this you have to reverse the y (vertical) axes coordinate before applying imcrop():
imagefile="d:\Attila\PROJECTS\Scilab\Stackoverflow\mixer_crop.jpg";
I=imread(imagefile);
I1G=rgb2gray(I);
scf(0); clf(0);
ShowImage(I1G,'mixer');
rect1=rubberbox();
imheight=size(I1G,"r"); //image height
rect1(2)=imheight-rect1(2); //reverse y axes coordinates (0 is at top)
ROI1=imcrop(I1G,rect1);
scf(1); clf(1);
ShowImage(ROI1,'ROI1');

Antialiasing in Qt's QGraphicsScene make overlapping lines darker

When using anti-aliasing rendering in Qt's QGraphicsScene, there is a behavior that makes drawings appear not as expected: overlapping lines become darker. I could not see any description of this behavior in the documentation, and I cannot find a way to disable it.
For example if I want to draw such a polygon:
Because of the number of points, it is impossible not to have overlapping lines - fine. But because anti-aliasing is activated, some borders appear 'thicker' than others.
Is there any way to avoid this and have anti-aliased lines that can overlap and yet at the same time be rendered without getting darker?
I know of course that I can redefine the paint() function and draw manually individual lines that do not overlap, but this is what I want to avoid. I am using Pyside and this would significantly slow down the application, due to the high frequency at which paint() is being called.
EDIT Fixed by defining the object shape using QPainterPath / QGraphicsPathItem instead of QPolygon / QGraphicsPolygonItem. In that case the moveTo function allows to avoid lines that overlap.
Another thing you could try is adding half a pixel to your coordinates (not dimensions). This fixed the anti-aliasing issue for me.
XCoord = int(XValue) + 0.5
YCoord = int(XValue) + 0.5
Also make sure that before that you have integer pixel values.

How to get the position of the first and the last tick mark in a Qslider?

I want to draw a tick mark for a qslider in paintEvent, so I should get the exact position of each tick mark. As you know, the handle of slider takes some space, so the first tick mark does not sit at the left/top position of the slider, there is offset of several pixels. Same thing happens to the last tick mark which indicates the maximum value. I want to know how many pixels of the space? (On win and mac, the handle are not in the same width)
If you have not yet done so, download the Qt source code and copy how they do it. You will want to look in the various Q...Style classes, i.e QMacStyle, QWindowsXPStyle, etc. Some of the key calculations come from:
QStyle::sliderPositionFromValue() method
QStyle::pixelMetric(QStyle::PM_SliderTickmarkOffset, ...)
Look in the various drawComplexControl methods for case CC_Slider:, where slider controls are drawn. In the Qt 4.7 code, this starts on line 2699 in qwindowsxpstyle.cpp, for example.

Resources