Qt: background for QtAbstractItemView (QTableView) while editing an entry - c++

I have the following question.
My QTableView has background color set to black and color (of contents) to white. So, white text appears on a black background - everything seems to be correct. However, when editing (typing in editing mode) content color is changed to black and it becomes completely invisible due to black background, but editing works fine. After confirming - color reverts back to white. How to set color of currently-being-edited text to white (preferably via stylesheets) or stop such change in this case?

You have to use the :edit-focus and/or :focus states in your stylesheet.
QTableView:edit-focus {
// style here
}
For a list of all available states have a look here

Setting palette worked finally.
QPalette palette;
palette.setColor(QPalette::Text, Qt::white);
qApp->setPalette(palette);

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.

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.

Adding/resizing a background image to centralWidget in Qt

I'm new to Qt. I searched for my question on multiple sites, but I couldn't find an answer. How can I add an image to centralWidget?
I tried:
MainWindow w;
w.centralWidget()->setStyleSheet("image: url(image)");
it worked fine but the image isn't stretched for the entire window/widget. How can I resize the image through setStyleSheet?
I want to display an image in the background and not the gray color, when the application opens. I tried changing the color. That worked, but it doesn't look good with buttons and labels.
If you want it to stretch for the entire widget use background-image, but I'm guessing what you probably want is an image that expands in one direction, either vertically or horizontally, in that case use background-position to fix it to one of the borders of your widget:
image: url(:/path/to/image);
background-position: bottom left;

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.