#include <QtGui>
#include <QWidget>
{
public:
protected:
{
semiTrans.setAlpha(50);
p.fillRect(rect(),semiTrans);
p.fillRect(0,height()/2 - 5,width(),5, m_color);
}
private:
};
int main(int argc, char * argv[])
{
TestWidget l1(Qt::black,&w);
l1.setGeometry(0,0,100,20);
TestWidget l2(Qt::red,&w);
l2.setGeometry(10,0,100,20);
TestWidget l3(Qt::green,&w);
l3.setGeometry(20,0,100,20);
TestWidget l4(Qt::yellow,&w);
l4.setGeometry(30,0,100,20);
l2.stackUnder(&l1);
l3.stackUnder(&l2);
l4.stackUnder(&l3);
w.resize(130, 40);
w.show();
return app.exec();
}
#include <QtGui>
#include <QWidget>
class TestWidget : public QWidget
{
public:
TestWidget(QColor color, QWidget *parent) : QWidget(parent),m_color(color) {}
protected:
void paintEvent(QPaintEvent *)
{
QPainter p(this);
QColor semiTrans = m_color;
semiTrans.setAlpha(50);
p.fillRect(rect(),semiTrans);
p.fillRect(0,height()/2 - 5,width(),5, m_color);
}
private:
QColor m_color;
};
int main(int argc, char * argv[])
{
QApplication app (argc, argv);
QWidget w;
TestWidget l1(Qt::black,&w);
l1.setGeometry(0,0,100,20);
TestWidget l2(Qt::red,&w);
l2.setGeometry(10,0,100,20);
TestWidget l3(Qt::green,&w);
l3.setGeometry(20,0,100,20);
TestWidget l4(Qt::yellow,&w);
l4.setGeometry(30,0,100,20);
l2.stackUnder(&l1);
l3.stackUnder(&l2);
l4.stackUnder(&l3);
w.resize(130, 40);
w.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks