How to add a myOwn-background image to QPlainTextEdit? - c++

For example, if you create a simple plaintextedit, the background is just white. How do I change white background with my own image?

In design edit, you can set the styleSheet in properties of QWidget. In c++ code you can set the background using QSS, for example, setting
‍‍‍‍background-image: URL("path/image.png");:
myWidget->setStyleSheet("background-image: URL('path/image.png')");

Related

Set background color for QTabBar beyond tabs?

Simple as the question title, I have a QTabWidget and I wanted to set the background color for the QTabBar area, and this is how I do it:
ViewTabs->tabBar()->setStyleSheet("background-color: rgb(85,85,85)");
I expected this to set the back ground for the whole bar, but instead it sets the background on tabs only as in the attached picture.
How do I make the background color take effect even beyond the tabs? I'm using QT 5.7 with C++.
You can try to change the background color manually in the UI interface by clicking on "palette" in the proprieties.
It's easier to handle colors this way.

Color the Image setting on QProgressBar

Actually I set an image on a QProgressBar and want to change the color of image according to selected part of QProgressBar.
I tried covering my image with QProgressBar color but that fills the image, but as my image is not a rectangle it color the whole QProgressBar and not just the image.
Is it possible to change color of image only using qt (with C++)
You are looking for Qt Style Sheet Documentation. You can customize your own QProgressBar, and add your own setProgress() function which should update the value property. You could modify the image background, the border, margins... depending of the value of the current value.
See QSS examples for more detail: Example Style Sheet

Qt changing the background color of QWidget using palette doesn't work

I want to change the background color in a custom subclass of QWidget.
Here is the code:
WorldView::WorldView(QWidget *parent) : QWidget(parent)
{
QPalette p(palette());
p.setColor(QPalette::Background, Qt::black);
setAutoFillBackground(true);
setPalette(p);
}
But it doesn't work as expected. The background color remains unchanged.
I don't know why.
As you can read in the documentation, QPalette::Background is obsolete. Use QPalette::Window instead. Note that some widgets use some other role for the background. See the QPalette::ColorRole documentation
Also:
Warning: Some styles do not use the palette for all drawing, for
instance, if they make use of native theme engines. This is the case
for both the Windows XP, Windows Vista, and the OS X styles.
In this case I suggest to use style sheets. See Qt Style Sheets Reference
However, if WorldView is a custom widget, with your custom paintEvent, it's up to you to draw the background
Use QPalette::Base instead of QPalette::Background
QPalette p(palette());
p.setColor(QPalette::Base, Qt::lightGray);
setPalette(p);
For some reason custom widget uses QPalette::Base for filling backgound
setStyleSheet('background-color:black;')
If the palette color doesnt work then it can have four reasons you should check
you have set the colors from style sheets which i don't recommend at all or maybe you have set the parents stylesheet
your color role in the palette doesnt match
make sure the palette is set for widget and i dont recommend to set palette for every widget unless you really wanted to, you should set the palette for your application
or maybe your window manager is forcing colors and palettes dont work at all
Thats all i got in my mind, if you know more, please edit this answere and add it to items

Changing TabControl tab title text background color c++

I am using Visual Studio 2005, C++, and I have a tabcontrol with a couple tabs. I have changed the color of each tab to have a back color of Transparent, to match the color of the rest of the program (Control grey), however the color behind the text for the title of the tab is white. Is there any way to change this?
A tab control draws itself according to the currently selected windows theme. Which ignores a custom color. This isn't something you ought to change, you typically want to honor the user's attempt to style the windows according to her selected preference.
If you really do want to override it then you can use custom drawing, the TCS_OWNERDRAWFIXED style flag and the WM_DRAWITEM message. Beware that drawing with a transparent color isn't going to work.

Custom draw CTreeCtrl: how to add font strike through?

I have implemented custom draw for an CTreeCtrl in my MFC Smart Device program. I have successfully changed the color of specific nodes of the CTreeCtrl. I am now trying to understand how to get the default font used to draw text in the control so I can add a strike-through to the font for certain nodes. How would I go about getting the default font used to draw text in the CTreeCtrl and apply a font strike-through to the font?
Use GetFont() to get the font of the control. Strike-through can't be done with ::DrawText AFAIK, but it's easy to just add a GoTo()/LineTo(). You can use GetTextExtent() to get the size of the bounding rectangle and derive the left/right of the strike through line from that.