关于QSplitter在样式表中鼠标悬浮失效的解决方法:
#include "widget.h"
#include <QSplitter>
#include <QTextEdit>
#include <QVBoxLayout>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
QWidget *leftWidget = new QWidget;
QWidget *rightWidget = new QWidget;
QVBoxLayout *leftLayout = new QVBoxLayout(leftWidget);
QVBoxLayout *rightLayout = new QVBoxLayout(rightWidget);
leftLayout->addWidget(new QTextEdit);
rightLayout->addWidget(new QTextEdit);
QSplitter *splitter = new QSplitter;
splitter->addWidget(leftWidget);
splitter->addWidget(rightWidget);
layout->addWidget(splitter);
this->setStyleSheet("QSplitter::handle{"
"background-color: rgb(100, 100, 100);"
"}"
"QSplitter::handle:hover{"
"background-color: rgb(200, 100, 100);"
"}"
"QSplitter::handle:pressed{"
"background-color: rgb(70, 70, 70);"
"}");
}
Widget::~Widget()
{
}
程序运行效果如下:
此时QSplitter鼠标悬浮的样式是失效的,
解决办法是添加下面的代码
splitter->handle(1)->setAttribute(Qt::WA_Hover, true);
添加后效果如下: