How to set dark mode on QWebEngineView? - c++

I tried all options found here: 1, 2, 3
but dark theme still not being applied.
Testing on Qt 6.4 and Windows 10.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS",
// "--blink-settings=darkMode=4,darkModeImagePolicy=2");
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--force-dark-mode");
//qputenv("QTWEBENGINE_CHROMIUM_FLAGS",
// "--blink-settings=darkModeEnabled=true,--blink-settings=darkMode=4,darkModeImagePolicy=2,--force-dark-mode,--blink-settings=forceDarkModeEnabled=true,darkmodeenabled=true");
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "blink-settings=darkMode=4,darkModeImagePolicy=0");
auto web = new QWebEngineView(this);
web->setUrl(QUrl("https://www.google.com/"));
}

Related

Failed when using drawText() in main() function

This is my code:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QRect r(0,8,32,16);
QImage img(32,32,QImage::Format_RGBA8888);
img.fill(Qt::Red);
QPainter p;
p.begin(&img);
QPen pen;
pen.setColor(QColor(0,0,0));
p.setPen(pen);
p.drawText(r,QString::number(i));
p.end();
QString str;
str.clear();
str.append("../../bmp/");
str.append(QString::number(2));
str.append(".bmp");
img.save(str);
return a.exec();
}
When gose to p.drawText(r,Qt::AlignCenter,QString::number(i));,Qt reports Error - RtlWerpReportException failed with status code :-1073741823.
But if I use other functions like drawRect or drawLine ,no faults are reported, why?
Font support must be part of GUI subsystem, both Qt framework-wise and platform-wise, assuming it's a XWindows application, Wayland or MS Windows.
Try replace QCoreApplication with QApplication and add GUI to configuration. Sadly, in case of Linux platform, you would require an active GUI server available.

C++ gtkmm 3 HeaderBar and Notebook with autohide animation

How can I:
1) properly set Gtk::Notebook in Gtk::HeaderBar like:
window.add(box);
2) implement autohide tabs ( animated like css transitions with scale(0) and scale(1) ) ?
My code:
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main app(argc, argv);
Gtk::Window window;
window.set_default_size(200, 200);
Gtk::HBox box;
Gtk::HeaderBar titlebar;
Gtk::Notebook notebook;
Gtk::TextView text;
notebook.append_page(text, "First");
box.pack_start(notebook);
titlebar.set_custom_title(box);
window.set_titlebar(titlebar);
window.show_all_children();
return app.run(window);
}

Program crashes when play video with QWebView

Here is the code
#include <QApplication>
#include <QtWebKitWidgets/QWebView>
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
QWebView view;
QCoreApplication::addLibraryPath("./plugins");
view.settings()->setAttribute(QWebSettings::PluginsEnabled, true);
// crash here
view.load(QUrl("http://hon.qq.com/act/20140320video/Aluna.html"));
// OK to show youtube
//view.load(QUrl("http://www.youtube.com/watch?v=KMU0tzLwhbE"));
view.show();
return app.exec();
}
It crashes when play video on hon.qq.com, but works well playing video on Youtube.

Library requires QApplication. How to use QApplication in Qt Quick project?

I have a Qt Quick project and I just added some source files. When trying to build I get the error message:
QWidget: Cannot create a QWidget without QApplication
Since I have a Qt Quick project I use the QGuiApplication. QApplication is a subclass of QGuiApplication. How do I make QApplication available to the newly added sources? Or how do one solve it when one have a Qt Quick and a QWidget?
The source files are the QCustomPlot library which shows a graph.
EDIT:
main.cpp:
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
//Register C++ classes with QML
qmlRegisterType<Bluetooth>("Bluetooth", 1, 0, "Bluetooth");
//Set start QML file
viewer.setMainQmlFile(QStringLiteral("qml/test/main.qml"));
//New Code:
// generate some data:
QWidget widget;
QCustomPlot * customPlot = new QCustomPlot(&widget);
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i=0; i<101; ++i)
{
x[i] = i/50.0 - 1; // x goes from -1 to 1
y[i] = x[i]*x[i]; // let's plot a quadratic function
}
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph(0)->setData(x, y);
// give the axes some labels:
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot->xAxis->setRange(-1, 1);
customPlot->yAxis->setRange(0, 1);
customPlot->replot();
//New Code End
//Show GUI
viewer.showExpanded();
return app.exec();
}
Error:
QML debugging is enabled. Only use this in a safe environment.
QWidget: Cannot create a QWidget without QApplication
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
The key concept is QWidget::createWindowContainer(). Try the following code:
#include <QQuickView>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQuickView *view = new QQuickView();
QWidget *container = QWidget::createWindowContainer(view, this);
container->setMinimumSize(200, 200);
container->setMaximumSize(200, 200);
container->setFocusPolicy(Qt::TabFocus);
view->setSource(QUrl("qml/test/main.qml"));
...
}
You can find the details on the following posts:
Introducing QWidget::createWindowContainer()
Combining Qt Widgets and QML with QWidget::createWindowContainer()

How to start a GUI application in the background?

How can I prevent a QApplication with a QMainWindow from stealing the keyboard focus when it starts? I'd like it to become active only after clicking on or alt-tabbing to it.
You could use showMinimized() instead of show() for you main window.
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow w;
w.showMinimized();
return app.exec();
}