16,815
社区成员




#include "test7.h"
#include <QDebug>
test7::test7(QWidget *parent) : QWidget(parent)
{
this->resize(500, 300);
this->setAutoFillBackground(true);
t1 = new QWidget(this);
t1->show();
t1->setAutoFillBackground(true);
t1->setStyleSheet("QWidget{background:red;}");
t2 = new QWidget(this);
t2->show();
t2->setAutoFillBackground(true);
t2->setStyleSheet("QWidget{background:green;}");
t3 = new QWidget(this);
t3->show();
t3->setAutoFillBackground(true);
t3->setStyleSheet("QWidget{background:blue;}");
t4 = new QWidget(this);
t4->show();
t4->setAutoFillBackground(true);
//t4->setStyleSheet("QWidget{background:black;}");
t1->setGeometry(0, 0, 200, 100);
t2->setGeometry(0, 0, 100, 200);
t3->setGeometry(100, 100, 100, 100);
t4->setGeometry(100, 100, 100, 100);
}
void test7::moveEvent(QMoveEvent *)
{
qDebug()<<t1->visibleRegion()<<t2->visibleRegion()<<t3->visibleRegion()<<t4->visibleRegion();
qDebug()<<this->visibleRegion();
}
QRegion(null) QRegion(null) QRegion(null) QRegion(null)
QRegion(null)
QRegion(0,0 200x100) QRegion(0,0 100x200) QRegion(null) QRegion(0,0 100x100)
QRegion(size=4, bounds=(0,0 500x300) - [(0,0 500x100), (0,100 100x100), (200,100 300x100), (0,200 500x100)])
能不能获得有效遮挡,主要看背景色是不是空的。显然这个背景色并不是用QSS设置的,那么还有个QPaintEvent。
改造t4:
class tt : public QWidget
{
Q_OBJECT
public:
tt(QWidget *parent = 0):QWidget(parent){}
protected:
void paintEvent(QPaintEvent *)
{
QPainter p(this);
p.fillRect(this->rect(), Qt::yellow);
}
};
t4 = new tt(this);
QRegion(null) QRegion(null) QRegion(null) QRegion(null)
QRegion(null)
QRegion(0,0 200x100) QRegion(0,0 100x200) QRegion(null) QRegion(0,0 100x100)
QRegion(size=4, bounds=(0,0 500x300) - [(0,0 500x100), (0,100 100x100), (200,100 300x100), (0,200 500x100)])