I want to display a fullscreen transparent image anytime there is an active menu button in cocos2d. How do I do that?
If you're looking to provide a popup dialog underlay, you can use CCLayerColor:
CCLayerColor* underlay = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)];
[self addChild:underlay z:(something less than your button's z)];
If it has to be a specific image, initialize the image and do the second line above using your CCSprite.
Related
Is there an efficient way of removing the frame and setting the background colour to transparent in Qt? Another thing I would like to make is to have the window being "moveable" too i.g. whenever I press and and hold the left mouse button I can move the window wherever I like.
Graphically to express the result I would like to achieve.
----------
Solution in order to make it "moveable": https://forum.qt.io/topic/34354/solved-frameless-window-dragging-issue/2
First you have to set the window flag (i do this in an overloaded QDialog::exec):
setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
(just add Qt::FramelessWindowHint to your window flags)
Then you add transparent background:
setAttribute(Qt::WA_TranslucentBackground);
...and make sure autoFillBackground is not set (uncheck in Designer if checked)
If you need to add a shadow, simply add a DropShadowEffect to the widget which creates the backgroud rounded rectangle:
auto dropShadow = new QGraphicsDropShadowEffect;
dropShadow->setOffset(0);
dropShadow->setBlurRadius(40);
dropShadow->setColor(QColor(0, 0, 0, 180));
ui.backgroundWidget->setGraphicsEffect(dropShadow);
The shadow is painted on the widget itself, so you need additional space around your background widget. I.e. if your BlurRadius is set to 40 you should set a 40 pixel margin:
layout()->setMargin(40);
How can I get the pressed background color of a QPushButton?
if (isDown())
_BGColor = <pressed background color>; // how to get this???
else
_BGColor = palette().color(QPalette::Background); // this is to get the idle backcolor
Thanks in advance!!!
It's very difficult (if not impossible) to find a way to get the backgound color of a button when it's pressed, because it depends on the style, and it's not guaranteed that the style respects the palette.
However I suggest two different approaches:
You can set you own background color using style sheets (simpler) or implement the painting of the button yourself, using styles or reimplementing paintEvent(). See Customizing QPushButton
To paint over the button with the inverse color, you can set a composition mode to the painter in order to get the inverse color.
For example:
painter.setPen(QColor(255, 255, 255));
painter.setCompositionMode(QPainter::RasterOp_SourceAndNotDestination);
(note that using this example, the inverse color of middle grey (128, 128, 128) is exactly the same color)
See QPainter::CompositionMode
I'm creating an application for capturing the screen or a part of it, and for that I need to select the part of the screen I want to capture.
The idea is to create a fullscreen semi-transparent window and draw thing on it so the user can see what he is doing. I have a working implementation where the selected area is dislayed as a wxPanel, but I want to rewrite it to paint everything to the main wxPanel manually.
frame = new wxFrame(NULL, -1, "", wxPoint(0,0), wxSize(0,0), wxSTAY_ON_TOP|wxFRAME_NO_TASKBAR|wxFRAME_SHAPED);
panel = new wxPanel(frame, -1);
SetTopWindow( frame );
panel->Bind(wxEVT_KEY_DOWN, &wxMiniApp::OnKeyDown, this);
panel->Bind(wxEVT_KEY_UP, &wxMiniApp::OnKeyUp, this);
panel->Bind(wxEVT_LEFT_DOWN, &wxMiniApp::OnMouseStart, this);
panel->Bind(wxEVT_LEFT_UP, &wxMiniApp::OnMouseEnd, this);
panel->Bind(wxEVT_MOTION, &wxMiniApp::OnMouseMove, this);
panel->Bind(wxEVT_PAINT, &wxMiniApp::OnPaintPanel, this);
panel->SetFocus();
panel->SetBackgroundColour(wxColor(0,0,0,100));
panel->SetBackgroundStyle(wxBG_STYLE_PAINT);
frame->SetBackgroundColour(wxColor(0,0,0,0));
frame->Show();
frame->ShowFullScreen(true);
I use panel to capture the mouse/keyboard events and I want to do the painting there too, but I don't know how to do this.
I want to have semi-transparent black background and the selected area should be transparent white or even fully transparent (without the black background).
The result of every attempt was that either it draw a solid color background or I got the famous WinXP lag effect.
Can you give me a basic OnPaintPanel(wxPaintEvent &event) implementation using x, y, with, height of the selected area (can be in wxPython too, if you're more comfortable with it) ?
You need to use SetTransparent(), wxDC doesn't support using alpha transparency anyhow (wxGraphicsContext does but it wouldn't help here).
I'm trying to creat a Dicom GUI Toolkit where the user selects some dicom images and the image of first dicom image from the selected ones will be shown. Then the user clicks on the image and the image pops out with bigger image window. In this shown bigger image, the image will consist of a red colored rectangle that contains necessary regions of the Dicom image while the unnecessary region is outside the rectangle. The user should then have the option to change the rectangle by mouse.
Until now, I have been able to show the big dicom image with the rectangle in it using QLabel which is by the following code snippets.
void MainWindow::showBigImage()
{
QPixmap bigimage;
bigimage.load(imageName.c_str());
QPainter painter(&bigimage);
painter.setPen(Qt::red);
QRectF rect(xmin, ymin, xmax, ymax);
painter.drawRect(rect);
QSize bigsize = ui->bigImageLabel->size();
ui->bigImageLabel->setPixmap(bigimage.scaled(bigsize, Qt::IgnoreAspectRatio, Qt::FastTransformation));
ui->bigImageLabel->show();
}
and the big image on the app looks like the following:
Can you please suggest me how I should now make the rectangle editable by the user where the user can set the existing red rectangle as per his or her wish?
I also tried similar thing using QGraphicsView and QGraphicsScene with the following code:
void MainWindow::showBigImage()
{
QGraphicsScene* scene = new QGraphicsScene;
scene->addPixmap(bigimage);
ui->bigImageView->setScene(scene);
ui->bigImageView->show();
}
And this code gives me the following look:
As you can see, I could not fit the image to the boundaries of QGraphicsView, could you suggest me how to do it? Could you also suggest me how to add the red rectangle(that I showed in the example using QLabel) on the QGraphicsView without adding the rectangle on the QPixmap?
In order to get the red selection rectangle, Qt provides the class QRubberBand. The docs state:
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary.
By subclassing the image object and implementing the mouse handling functions, to create the rubber band on mousePressEvent, update its position on mouseMoveEvent and grab its final rect on mouseReleaseEvent, the QRubberBand will simplify the problem.
If you want the QRubberBand to show all the time, just create it when you display the enlarged image and don't hide it on releasing the mouse button.
As for displaying the image in the QGraphicsView, the code you displayed doesn't set the geometry of the QGraphicsScene and QGraphicsView, so you're seeing a border. If you don't want that, you should set them accordingly. Also note that QGraphicsView has a function fitInView, which you could use, after having retrieved an area from the QRubberBand, in order to zoom into the selected area.
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