A simple solution is to create a QProxyStyle, so all the widgets will be affected without the need to inherit from that class.
#include <QtWidgets>
class CursorStyle: public QProxyStyle
{
public:
using QProxyStyle::QProxyStyle;
int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const override
{
if(metric == PM_TextCursorWidth)
return 0;
return QProxyStyle::pixelMetric(metric, option, widget);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
CursorStyle *style = new CursorStyle(a.style());
a.setStyle(style);
QWidget w;
QVBoxLayout *lay = new QVBoxLayout(&w);
lay->addWidget(new QLineEdit);
lay->addWidget(new QTextEdit);
w.show();
return a.exec();
}