Can anybody tell me if there is any way of adding a background image to property page in MFC? I'm able to set the background image for dialog but not able to do the same for property page?
Inherit CPropertyPage and override OnEraseBkgnd. You can paint a bitmap into the provided device context.
Related
I need to create a toggle button in qt and it should look like the below image. It should show the ON image when it is turned on and remain at this state until it is toggled again. It should show the OFF image in the off case. Please help me on this.
You can use images as an icon (sadly, it won't scale with button by default), create a class which would paint those images in the handler for paint event, or you can use those images in QSS stylesheet. QSS is CSS 2.0 analog for Qt's GUI elements.
Note that after using stylesheet all changes to visuals of said element should be done through changes to stylesheet as well.
THose styles can be set through form editor by right-clicking a widget and choosing "Change stylesheet" or through code directly by calling setStyleSheet, depending which workflow you prefer.
button->setStyleSheet(
"QPushButton { border-image: url(:/Resources/chbUnchecked.png); }"
"QPushButton::checked { border-image: url(:/Resources/chbChecked.png); }" );
border-image Scales image to border limits, replacing standard border.There is also a background-image which fills widget's surface with regular repeats.
To limit this change only for checkable buttons:
button->setStyleSheet(
"QPushButton[checkable="true"] { border-image: url(:/Resources/chbUnchecked.png); }"
"QPushButton::checked[checkable="true"] { border-image: url(:/Resources/chbChecked.png); }" );
:/Resources/ is a path within app's resources.
QSS syntax: https://doc.qt.io/Qt-5/stylesheet-syntax.html
Note that QSS have selectors, so it's it have same "Cascading" ability as CSS. You can assign styles bulk based on hierarchical location on GUI, class-inheritances, class names, quasi-states and names.
If you set style above to a window, all instances of QPushButton within that window would have said style. If you define a new class for such Button, you can use its name instead of standard button class, although QSS for base class would apply to it.
the easiest way is to add the on-off images to your project as resources
then set the button as checkable and in its properties set the images to be rendered when is selected or not..(under icon -> selected on and selected off)
of course you have create images with a properly geometry... in the screenshot they look pretty small because I borrow them from your post..
:)
I have created some (CMFCToolBar) toolbars and added buttons and icons to them. I read on Microsoft's official website that CMFCToolBar takes 23x22 button size and 16x15 icon size (ref: link).
If I use 16x15 for the icons, then icons appear blurry. This is because the icons are originally with size 16x16. I used the function SetSizes(CSize (23,23), CSize(16,16)) to change icon size but the icons do not appear right:
Is there another way to set icon and button size?
Update
I called the SetSize function before create toolbar but the icon still appear a little blurry:
I want to know if there is a way to set Icon/button Transparent or make it clear like we can set toolbar transparent through TBSTYLE_TRANSPARENT in CreateEx function.
SetSizes is a static function that affects the complete library.
It should be called before you create any toolbar or menu object.
Best location is in InitInstance of you applicxation.
But my tipp: Use the sizes that are recommended! 16x15 and 23x22....
Transparency can be done with standard 32bit RGB/A bitmaps.
If you have a 16 color bitmap you should use RGB(192,192,192) as the standard color for the background. It is automatically replaced with the needed background color.
This has been answered here too.
I have a child window derived from CMDIChildWndEx named as CTestTooltipMdiChildWnd, on CTestTooltipMdiChildWnd titlebar, I have drawn a custom icon which is initially disabled.
When user mouse over on this custom icon, I should get a tooltip displayed.
I get rect value of custom icon.
Any input how can I do this.Can anybody suggest any link where tutorial is available to understand.
I have a class derived from CPropertySheet. Please let me know how can I change the font of this propertysheet tab along with fonts in all pages. Currently they used system font only.
Also I would like the dialog box to come up at specific location on screen and remain there only. Please let me know how can I change location of propertysheet dialog when it is getting initialised.
Thanks
CPropertySheet inherits the SetFont method from CWnd. You could call this method from CPropertySheet::OnInitDialog. Do the same thing in the pages to set their font.
In my app, pressing a button activates a dialog box. This dialog box contains a rich edit control 2.0. I want to set the background color of this rich edit control 2.0 to red on its creation,i.e, the default background color of this rich edit control should be red (instead of white, which is the actual default). I'm thinking of using SetBackgroundColor() function to set the color, but I want to know where to place the code so that it is executed when the rich edit control 2.0 is created.
Thanks
Can't do it when it is created. You have to do it after it is created. If the control is in a dialog box, generally, you will do it this way:
1) Override DoDataExchange() in your dialog box class and put an entry for DDX_Control(pDX, IDC_RICHEDI1, m_richedit) -- substitute proper id's and variable names
2) Override OnInitDialog() in your dialog box. Using m_richedit (or whatever you name it), set the background color with SetBackgroundColor. It may not do what you want and may have to look into SetDefaultCharFormat, SetParaFormat, or SetSelectionCharFormat.