无法创建透明QFrame

时间:2012-12-04 17:24:50

标签: transparency qwidget

我想创建没有背景的QWidget;我想为它添加一个透明的QFrame。这是我的代码:

QWidget  *change_impl_win = new QWidget();
QHBoxLayout *mainLayout = new QHBoxLayout(change_impl_win);
QVBoxLayout *vbox_l = new QVBoxLayout();

QFrame *back_frame = new QFrame();
back_frame->setBackgroundColor(QColor(125, 125, 125, 125));
QHBoxLayout *frame_hbox = new QHBoxLayout(back_frame);
frame_hbox->addLayout(vbox_l);

mainLayout->addWidget(back_frame);

QGroupBox *newImplant = new QGroupBox("");
QGridLayout *layoutNewImplant = new QGridLayout;
newImplant->setLayout(layoutNewImplant);
vbox_l->addWidget(newImplant);

QRadioButton *cb_ob_rb = new QRadioButton("Up", change_impl_win);
QRadioButton *cb_un_rb = new QRadioButton("Down", change_impl_win);

layoutNewImplant->addWidget(cb_ob_rb);
layoutNewImplant->addWidget(cb_un_rb);

QLabel* lengthLabel = new QLabel("Length:");
QSpinBox *cb_implantLength = new QSpinBox;
cb_implantLength->setRange(1, 20);
cb_implantLength->setSingleStep(1);
cb_implantLength->setSuffix("  mm");

layoutNewImplant->addWidget(lengthLabel, 2, 0);
layoutNewImplant->addWidget(cb_implantLength, 2, 1);

QLabel* diameterLabel = new QLabel("Diameter:");
QSpinBox *cb_implantDiameter = new QSpinBox;
cb_implantDiameter->setRange(1, 20);
cb_implantDiameter->setSingleStep(1);
cb_implantDiameter->setSuffix("  mm");

layoutNewImplant->addWidget(diameterLabel, 3, 0);
layoutNewImplant->addWidget(cb_implantDiameter, 3, 1);

QPushButton *cb_apply_prop  = new QPushButton();
cb_apply_prop->setText("Apply");               
cb_apply_prop->setGeometry(400, 0, 200, 40); 
cb_apply_prop->setFont(QFont("Charter",13));
cb_apply_prop->setAutoFillBackground(true);

frame_hbox->addWidget(cb_apply_prop);

change_impl_win->setAttribute(Qt::WA_TranslucentBackground);
change_impl_win->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);

change_impl_win->show();

但是,我看不到透明的QFrame。我看到只有控件添加到没有背景的QWidget。请告诉我哪里弄错了。谢谢。

0 个答案:

没有答案