MyDialog::MyDialog(QWidget* parent, Qt::WindowFlags f)
: QWidget(parent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
, _pixmap(new QPixmap(myPngFile))
{
QPalette palette;
palette.setBrush(this->backgroundRole(), QBrush(*_pixmap));
this->setPalette(palette);
setFixedSize(_pixmap->size());
}
myPngFile define the png path. The problem is the transparent part in png file showed black when I show MyDialog, how do I correct it to load myPngFile?
I am using Windows platform with Qt4.8
Please do not use stylesheet.
Use
setAttribute(Qt::WA_TranslucentBackground);
Take a look at this:
specifically:
QPixmap aPixmap(":/splash.png");
QLabel* aWidget = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
aWidget->setAttribute(Qt::WA_TranslucentBackground);
aWidget->setPixmap(aPixmap);
aWidget->show();
And docs:
Creating Translucent Windows Since Qt 4.5, it has been possible to
create windows with translucent regions on window systems that support
compositing. To enable this feature in a top-level widget, set its
Qt::WA_TranslucentBackground attribute with setAttribute() and ensure
that its background is painted with non-opaque colors in the regions
you want to be partially transparent.
Platform notes:
X11: This
feature relies on the use of an X server that supports ARGB visuals
and a compositing window manager.
Windows: The widget needs to have
the Qt::FramelessWindowHint window flag set for the translucency to
work.
(This bold part you already do, but for future comers better to make it visible)
If you really don't want to use style sheets, your problem could be solved by overwriting the paint event of your MyDialog class like in the answer of this stackoverflow question:
Background image not showing on QWidget
But I would also recommend using style sheets for your problem.
I cannot understand why you do not want to use stylesheets since this it the preferred way. Use the setStylesheet method of QWidget
setStyleSheet("background-image: url(:/images/pixmap.png);");
Where pixmap.png will be located in the resource file under the images prefix. For more details check the Qt stylesheet examples.
Related
This is in reference to:
No Transparency on Visual Basic PictureBox
To Visual Vincent; First, I'd like to thank you for sharing your efforts with the community... Thank you very much!
I'm not very good at "Class" building. I've never implemented class modules very efficiently. I understand the principals, but tussle with mapping the properties and events before creation.
Anyway, does this example work in VB6? If so, how?
When I paste your example code into the class module code window, much of the text is red.
You can try my AlphaBlendImage control for VB6 built-in VB.Image control replacement w/ added support for transparency.
It supports both key-color transparency where you choose one color (e.g. magenta) to become transparent and true alpha-channel transparency like in PNG files.
You have to load PNG files with it's GdipLoadPicture function to preserve the alpha-channel transparency still by using built-in StdPicture instances. Take a look at the sample in test/basic directory for more info.
I am working on a Xamarin App compatible with all devices. I have a general question related to images. I am using Location Mark Image Icons to provide locations available on the Map. My issue is, Image has a white background which is also showing along with its background. I want to show only the Image.
Is this related to the designer to provide the image without background? Or as a developer, I can do something on it.
Xamarin.Forms doesn't delete your white background. What you need to do is following a small tutorial on how to use Adobe Photoshop for example and export your images as png, you might even consider which png type you need, there's 3 types of png:
png8
png24
png32
I won't be going deep in explaining each one of them, but you need to know that they all support transparency and could have a transparent background, however, you might notice some differences between them on the edges.
For example, png8 will give a small white border while png24 will not show that.
You can check this for example: https://helpx.adobe.com/photoshop-elements/using/optimizing-images-png-24-format.html
No, you can't do anything about it using Xamarin.Forms. You need to modify the image and remove the background (using Adobe Photoshop, etc.) and make sure to save it as .png.
If its simple white background you want to remove, You can utilise simple [MakeTransparent][1] method ofBitMap.
But this will remove all white coloured pixel. So IF your logo also contains white color, better you contact your designer.
I would like to show a logo with transparency at the top of my dynpro custom container using the cl_gui_picture.
At the moment I am using the class cl_ssf_xsf_utilities to get an bmp out of the BDS.
The last step is the method load_picture_from_url from cl_gui_picture.
Is it possible to load an image like a gif or something with transparency?
Thanks! =)
I expect the background color from the underlying SAP GUI Theme to appear. In the meantime I solved the problem by using the SAP Web Repository because it can handle GIF's with transparency. I used the function module "DP_PUBLISH_WWW_URL" to get the url for "cl_gui_picture".
In a win32 application, I want to have a button with an icon which looks gray when the button is disabled and 'brighter' when the mouse hovers.
I know I can create three bitmaps with an icon editor, but since the icon can be user selected and loaded from the disk, I would like to create the other two versions programmatically.
So, starting with a handle to an image, I would like to:
- Create a new image with all colors converted to grey.
- Create a new image with all colors shifted to white or yellow.
Can this be done using win32 api calls?
Examples in any language will be appreciated.
Maybe the good old DrawState function will suffice. (For some reason it is now listed as only available from Win2000 which is not true.)
And maybe not, in which case you might want to use SetColorAdjustment function.
If the icon is user-selected do you control the format? If not you'll probably want to incorporate an image library or external process like DevIL or Imagemagick which handle more formats than Microsofts API's are likely to..
What are the recommended colors for an application's background, button faces, etc.?
In the past I've just chosen a color scheme but I'd like to be more compatible with the Windows Accessibility Options, etc.
I see that VB6 has System Colors like Application Workspace.
Edit: I'd like to find an explanation of all of those colors (like what's the difference between Application Workspace and Window Background?
In my opinion, you should leave the colors as they are if you are using standard controls; they'll get the right color according to che current color scheme by themselves. You need to use the color constants only if you have to draw your own UI elements; in that case, the meaning of those constants is explained briefly in their documentation.
This PDF http://www.johnsmiley.com/cis18/Smiley009.pdf [ explanation of VB6 System Color values ]should help you. It lists all the system color constants and what they mean. For instance vbApplicationWorkspace is the "Background color of multipledocument interface (MDI) applications."
If you're interested in the whole MS Windows UI/UX guidelines, they are available online here and for download here. Page 618 deals with how to "Use theme or system Colors"
It depends on the language and framework you use. .Net for example has an entire SystemColors class full of static properties like SystemColors.Control that are 'changed' to the corresponding system color in runtime.
I think most office applications conform to the system colors, while most graphics intensive applications (e.g. games) use their own color scheme.
It is best if you try to use the colors of the current system (like the .NET SystemColors), that way if the user changes his settings (for example if he uses a high-contrast color scheme or some fancy black theme he likes) your application will adapt those colors and that way conforms to the users preferences/needs.