QSciScintilla Background Color - c++

I'm trying to change the color of the entire QSciScintilla editor widget. I've tried using the function
QSciScintilla::setPaper(const QColor &c)
but that seems to change only the color behind the text (see screenshot). How can I change the background color of the ENTIRE box?
Thanks in advance.

Calling setPaper on the QsciScintilla widget will have no effect if a lexer has been set.
Try using the setDefaultPaper function of the current lexer.

Related

How to add a myOwn-background image to QPlainTextEdit?

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')");

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.

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

QDockWidget::background-color not applied when docked

I have a QDockWidget:
I would like to alert the user to certain events by setting the background color of the title bar.
I have achieved this by setting the style sheet for my DockWidget:
void DockWidget::setCriticalAlert()
{
setStyleSheet("QDockWidget { background-color:red; }");
}
The result is this:
The problem is that the background-color doesn't get applied when the QDockWidget is docked:
How can I get the background color to be applied when the QDockWidget is docked?
This is a bug in Qt.
Issue 10537
Quoting from the linked issue:
The problem is that in QDockWidget::paintEvent, there is a
isFloating() condition before drawing PE_FrameDockWidget. We cannot
jsut remove this condition as it would break the other style (that
does not whish to draw frame when the dockwidget is docked) We cannot
either use PE_Widget to draw the frame as then it goes over the
dockwidget's title The solution is maybe to introduce a new
PE_FrameDockWidgetDocked primitive element. Or some
SH_DockWidget_DrawDockedFrame stylehint to draw the frame in every
cases.
a valid workaround seems to be to set the stylesheet of the parent, and use the class-and-id selector. Forgive the python formatted code but the concept is the same - in this case, 'dock' is a QDockWidget which has been given an object name using setObjectName(), and its parent, the QMainWindow, is 'self':
self.setStyleSheet("QDockWidget#"+str(dock.objectName())+"::title {background-color:red}")
In PyQt5.5, this works at runtime, i.e., can be changed on the fly.
I find a solution like this:
Firstly put a frame behind all the widgets of dockwidget's center widget, as the background.
Then set stylesheet for the frame.
By this way, we could change the background color of dockwidget.
Or you can extend the dockwidget and overwrite the function
void QDockWidget::setWidget(QWidget *widget)
using private/qdockwidget_h. and add a frame as this widget's father.

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.