How to change the background color of the whole console without affecting the text color in c++ on windows OS - c++

I am trying to make a function having a text color and a background color attribute. The text color attribute just sets the color of the text to follow while the background color has to change the background color of whole console window.
The problem is that the SetConsoleTextAttribute() function only changes the background color of a block of text but not of the whole console window. While the problem with system("Color code") is that it changes the color of any pre-written text also.
what I want to do is this:
int main()
{
setColor("Red","Blue");
//custom function setColor() to set text color Red and Console's color Blue.
cout << "This is Red text on a Blue console window" << endl;
setColor("Yellow","Black"); /*now the whole console's color should turn Black, the color
of pre-written text above remains Red and the color of text
to follow should be Yellow.*/
cout << "This is Yellow text on a Black console window, The previous text is still Red";
return 0;
}
I have tried mixing both system() and setConsoleTextAttribute functions to achieve this but I failed to preserve the color of pre-written text while changing color of the text to follow.
So, is there a way of making a function which does the same thing as the setColor() function did in this example?

You will need to implement this yourself. The Windows Console API can help, all the functions are documented here.
You can read the colors of the currently displayed characters with ReadConsoleOutputAttributes. You can change them to the new background color with WriteConsoleOutputAttributes.

Related

How do I change the text color of the inline breakpoint settings?

I use a dark theme, and I have my code "peek" background set to a dark color as well.
In VS2017, instead of the older dialog window you'd get when modifying a breakpoint, you get the settings inline instead, similar to how the "peek" bits look.
However, I can't find a way to change the text color of this area, so now I am trying to squint at dark grey text on a dark purple background. It seems as though the "peek" background color is shared with the breakpoint settings.
Is it possible to change this color?
Here's an image to show you what I mean:

How to set tab background color

I am trying to set the colour of all the white space in a tab that I have using QSS.
In the image you see what it currently looks like.
This next image is what happens if I use
"background-color:black;"
You can see that it HAS made the background black, but I want to fill in the surrounding white area too.
Anyone know how this is done?
I have my items collected together in various QHBoxLayout

Qt 5.3 QPlainTextEdit Change the QTextCursor color

I would like to change the cursor color under the QPlainTextEdit widget. I was able to set it's width to 6, but I want to change the color or it. Is it possible ?
QFontMetrics fm(font());
setCursorWidth( fm.averageCharWidth() );
//setCursorColor is what I need.
Thanks.
Edit:
Including the images to exemplify...
From this:
To this:
Thanks.
Edit2: Final Look
You can use QTextCharFormat to set the color of the text in your QPlainTextEdit. Use the QTextCharFormat::setForeground to set the color.
Then use a stylesheet to change the color of the cursor by using the color property.
QPlainTextEdit *p_textEdit = new QPlainTextEdit;
p_textEdit->setStyleSheet("QPlainTextEdit{color: #ffff00; background-color: #303030;"
" selection-background-color: #606060; selection-color: #ffffff;}");
QTextCharFormat fmt;
fmt.setForeground(QBrush(QColor(255,255,255)));
p_textEdit->mergeCurrentCharFormat(fmt);
Edit
You can change caret color with next stylesheet:
ui->plainTextEdit->setStyleSheet(
"QPlainTextEdit"
"{"
"color: yellow;"
"}"
);
But there is another problem, all text becomes with this color too. How to set new color to text but left old color for caret? I found this solution, maybe not the best: use html code:
ui->plainTextEdit->appendHtml("<font color = \"red\"> Sample Text</font>");
Result (as you want original color for caret and for text):
Now text has needed color but caret has special color. It is solution, but it is a little dirty for me, if someone will find better way to change color of text without changing caret color, please tell this.
You can change only main cursor under widget:
QPixmap pix("pathToPixmap");
QCursor cur(pix);
ui->plainTextEdit->viewport()->setCursor(cur);
Qt has next embedded cursors: http://qt-project.org/doc/qt-5/qt.html#CursorShape-enum
Qt has not any cursor with specific color, so you should use you own pixmap. You can use image with simple arrow but with another color (if it has alpha-channel then it is better)
There are many different cursors in the web.

c++ DrawText() font color and background color

How do I change the text color and font background color that is displayed when I use the DrawText() function?
Whenever I use the DrawText() function, I always output a present font as well as a "white" background color. I understand to change the font I must create the HFONT and use SelectObject to set the font, however... I did not find any color options in the CreateFont parameters (searched in msdn):
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183499(v=vs.85).aspx
Now, on msdn page for the DrawText() function (http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx) I found the following comment:
"The DrawText function uses the device context's selected font, text color, and background color to draw the text. "
And that is all I could find relative to text color and background color. From that sentence, I am unsure if I should be using some other GDI functions to select other objects that specify text color or background color (if those objects exist), nor am I sure if I missed something in the parameters for CreatFont().
QUESTION:
How do I change the text color and font background color that is displayed when I use the DrawText() function?

Set background color of entire window in PDCurses

wattron and a color pair only sets the background color of text when it is printed inside a window. What is the best way to set the background color of the entire window without filling it with spaces (i.e. a title or status bar)?
A call to wbkgd with a pointer to a WINDOW object and a color pair sets the background color of the window.