16,212
社区成员
发帖
与我相关
我的任务
分享
useredit->setStyleSheet(QString("background:(0,255,0,0);"));
passwdedit->setStyleSheet(QString("background:(0,255,0,0);"));
应为
useredit->setStyleSheet(QString("background:rgba(0,255,0,0);"));
passwdedit->setStyleSheet(QString("background:rgba(0,255,0,0);"));
QWidget* loginwidget = new QWidget;
// 窗口设定
setWindowTitle(tr("LOGIN"));
setFixedSize(this->width, this->height);
this->setCentralWidget(loginwidget);
titlelab = new QLabel;
// 必须先设置其大小,然后才能进行其它配置
titlelab->setFixedSize(this->width, 90);
titlelab->setFrameRect(QRect(0, 0, this->width, 90));
titlelab->setStyleSheet(QString("background-image:url(:/images/images/logo.png)"));
//titlelab->resize(img.width(),img.height());
QFont font;
font.setFamily(QString::fromUtf8("\345\276\256\350\275\257\351\233\205\351\273\221"));
font.setPointSize(12);
useredit = new QLineEdit;
useredit->setFont(font);
useredit->setFixedSize(130, 25);
useredit->setStyleSheet(QString("background:(0,255,0,0);"));
userlab = new QLabel;
userlab->setText(tr("USER NAME"));
userlab->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
userlab->setFixedSize(92, 20);
userlab->setFont(font);
userlab->setStyleSheet(QString("color: rgb(0,0,255);"));
userlab->setBuddy(useredit);
passwdedit = new QLineEdit;
passwdedit->setFont(font);
passwdedit->setFixedSize(130, 25);
passwdedit->setStyleSheet(QString("background:(0,255,0,0);"));
passwdlab = new QLabel;
passwdlab->setText(tr("PASSWORD"));
passwdlab->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
passwdlab->setFixedSize(92, 20);
passwdlab->setFont(font);
passwdlab->setStyleSheet(QString("color: rgb(0,0,255);"));
passwdlab->setBuddy(passwdedit);
// 用户名和密码
QFormLayout *userform = new QFormLayout(parent);
userform->addRow(userlab, useredit);
userform->addRow(passwdlab, passwdedit);
userform->setLabelAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
userform->setFormAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
// 设置水平控件间隔
userform->setHorizontalSpacing(4);
// 设置垂直控件间隔
userform->setVerticalSpacing(8);
// 设置外边框距窗口距离
userform->setContentsMargins(0, 0, 0, 0);
// 记住密码 登陆按钮
remembercheck = new QCheckBox;
remembercheck->setFont(font);
remembercheck->setFixedSize(100, 30);
remembercheck->setText(tr("Remember"));
loginbtn = new QPushButton;
loginbtn->setText(tr("Login"));
loginbtn->setFont(font);
loginbtn->setFixedSize(84, 30);
QHBoxLayout *btnlayout = new QHBoxLayout;
btnlayout->setContentsMargins(0, 0, 30, 0);
btnlayout->addWidget(remembercheck);
btnlayout->addWidget(loginbtn);
btnlayout->setStretch(0, 11);
btnlayout->setStretch(1, 9);
// 状态栏
statlab = new QLabel;
statlab->setFixedSize(320, 12);
statlab->setText(tr("Please input user and password..."));
font.setPixelSize(11);
statlab->setFont(font);
statlab->setStyleSheet(QString("color:rgba(191,58,224,255);background-color:rgba(160,184,166,255)"));
font.setPixelSize(12);
// 登陆窗口
QVBoxLayout *loginlayout = new QVBoxLayout;
loginlayout->setContentsMargins(0, 0, 0, 0);
loginlayout->addWidget(titlelab);
loginlayout->addLayout(userform);
loginlayout->addLayout(btnlayout);
loginlayout->addWidget(statlab);
这是我的代码
// like this
setStyleSheet("QLineEdit:hover { background: white }");