I want to draw in Picture Box control my purpose is picture box have scroll bar that I can draw in it bigger than what It's size I mean have scroll to move It's picture,
I try to draw something more than picturebox's size, It went to main frame panel my code is below.
void Cex133Dlg::OnBnClickedOk()
{
CDC *myDC = GetDlgItem(IDC_DRAWBOX)->GetDC();
myDC->Rectangle(10, 10, 20, 20);
}
You can draw with in the picture box. Definitely it will go outside the picture box frame, if you draw something more than picturebox's size. For that you can calculate the picture box Size, According to that you will draw your object.
You don't draw to the control -- you give it a bitmap, and it does its own drawing.
Hi you can look for http://www.codeguru.com/cpp/cpp/cpp_mfc/general/article.php/c14765 and mfc CScrollView
Related
I need to draw custom title bar, using Win10, VS2017, MFC, SDK10.0.16299.0.
When MyDialog::OnNcPaint() does not call CDialogEx::OnNcPaint(), the dialog frame is drawn incorrectly - the top corners are rounded while bottom corners are sharp, and dialog size increases in couple of pixels.
I need to keep the dialog in original size and shape. Any suggestions please ?
This is a problem I've been having for a while now. I'm trying to have a draggable rectangle to show the user an area that they've selected in my screenshot program. The reason I want this is for users to be able to select a portion of the screen that they want to take a screenshot of. I have tried the following method with little success:
void drawRect(){
HDC screenDC = ::GetDC(0);
::Rectangle(screenDC, 200, 200, 300, 300);
::ReleaseDC(0, screenDC);
}
Now, to give this method due credit, it does draw a rectangle to the screen in a way that I'd expect however once the dragging has stopped the rectangle persists. I've looked at ways of getting rid of this such as updating the windows where the rectangle continues to be shown however I haven't managed to remove it. Further to this problem since you must redraw the rectangle every monitor refresh and the rectangles persist, I am left with lots of rectangles being drawn all over the screen and I then have to mouse over or click on any windows these are drawn over to remove them.
Use DrawFocusRect instead. Drawing the same rect again removes it from the screen.
I guess there are lots of ways to achieve this. I have an application in which a video stream is shown over a custom QWidget that I have subclasses from QLabel, and painting frames using QPainter. Given that, is it possible to let the user to drag a rectangle over the image and retrieve the coordinates? The requirement is that the rectangle must be visible during the dragging.
Thanks in advance,
Have a look at QRubberBand. It allows you to place such a rect on top of e.g. a QLabel. The documentation also contains an example how to move and resize the rubberband using the mouse.
the QGraphicsView has the void setRubberBandSelectionMode ( Qt::ItemSelectionMode mode ) but i dont know if the QLabel has some similar feature ...
maybe you have to draw your own rectangle while the user drags the rectangle and catch it on mouserelease
soo long zai
In you widget you could track mouse pressed and released events and track where on the widget the corners of the selection rect are. For drawing the rectangle, I'd take a look at QStyle::drawFocusRect. I think the intent of that is to draw a rect you'd be able to see regardless of what's behind it.
Or perhaps try this:
QStylePainter painter(this);
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Background);
painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
Ok, I basically have randomly placed graphics items on a graphics scene. I open a window and display these items. When I resize the window, I want this items to stay the same size but reposition proportionally to the window size. How I did this was I subclassed the graphics view and then when there was a resize event, it sent the resize object to my graphicsscene object. I was then able to do something like this:
double scaleX = double(event->size().width())/double(event->oldSize().width());
double scaleY = double(event->size().height())/double(event->oldSize().height());
Then I used these values to do this:
derivedPointItem->setPos( derivedPointItem->pos().x() * scaleX,
derivedPointItem->pos().y() * scaleY );
This works ok, but it's not quite right if I resize the window really small or large. I think the problem is that the graphicsscene rect and the graphics view rect are not the same or something. Furthermore, I have a background which resizes to window size:
void roiwindow::drawBackground( QPainter* painter, const QRectF& rect )
{
this->setSceneRect(0,0,rect.width(),rect.height());
painter->save();
painter->drawImage(rect, *refimage);
painter->restore();
}
This is something I need in the program I'm writing. Also, it allows me to see if the resizing works. I basically can set the background to be a polygon, then place points on the edges of the polygon. When I resize the image to be very large or small the points are no longer on the vertices of the polygon althought they are somewhat close. Anyone know a better way to do this or a way to fix it? Thanks.
EDIT: Here's the project I'm working on:
dropbox.com/s/myxi8kvdl7x9ye2/ncorr.tar.gz
This method actually works (although I'm not sure if it's the best method to use...). Anyway, it ended up being a coding error due to the setPos() function. The setPos() function in my program worked by specifying the coordinates of the top left corner of the image rather than the center. This ended up causing some errors.
How can I draw a selection rectangle on my screen with Qt in X11?
I want to be able to drag a rectangle on my screen (outside of the application) and then save the whole rectangle.
Thanks in advance.
Part of the solution will involve using the grabWindow() function of QPixmap like so:
QPixmap::grabWindow(QApplication::desktop()->winId());
Qt has an example program for this here.
There rest of the solution, drawing the area to grab, can probably be achieved by either using a full screen transparent window to render a mouse drawn rectangle and then taking the section it outlines from the grabbed desktop image or using a full screen window with the entire grabbed screen painted on it.