2010年(21)
分类:
2010-03-10 17:47:42
#include#include
#include#include
#include#include
#include#include
#include#include
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QApplication app(argc, argv); QApplication app(argc, argv);
QWidget *window = new QWidget; QWidget *window = new QWidget;
window->setWindowTitle("QLineEdit"); window->setWindowTitle("QLineEdit");
QLabel *nameLabel = new QLabel("Name"); QLabel *nameLabel = new QLabel("Name");
QLabel *pwdLabel = new QLabel("Password"); QLabel *pwdLabel = new QLabel("Password");
QLabel *luckyLabel = new QLabel("Lucky Number"); QLabel *luckyLabel = new QLabel("Lucky Number");
QLineEdit *nameLine = new QLineEdit; QLineEdit *nameLine = new QLineEdit;
QLineEdit *pwdLine = new QLineEdit; QLineEdit *pwdLine = new QLineEdit;
pwdLine->setEchoMode(QLineEdit::Password); pwdLine->setEchoMode(QLineEdit::Password);
QLineEdit *luckyLine = new QLineEdit; QLineEdit *luckyLine = new QLineEdit;
luckyLine->setValidator(new QIntValidator(luckyLine)); luckyLine->setValidator(new QIntValidator(luckyLine));
QGridLayout *layout = new QGridLayout; QGridLayout *layout = new QGridLayout;
layout->addWidget(nameLabel, 0, 0); layout->addWidget(nameLabel, 0, 0);
layout->addWidget(nameLine, 0, 1); layout->addWidget(nameLine, 0, 1);
layout->addWidget(pwdLabel, 1, 0); layout->addWidget(pwdLabel, 1, 0);
layout->addWidget(pwdLine, 1, 1); layout->addWidget(pwdLine, 1, 1);
layout->addWidget(luckyLabel, 2, 0); layout->addWidget(luckyLabel, 2, 0);
layout->addWidget(luckyLine, 2, 1); layout->addWidget(luckyLine, 2, 1);
window->setLayout(layout); window->setLayout(layout);
window->show(); window->show();
return app.exec(); return app.exec();
} }
(1)当文本长度大于QLabel控件长度时,超过的文本部分不会显示出来。处理方法:
1、用QLineEdit代替原来的QLabel
2、去掉QLineEdit的frame
setFrame
(
false);3、用样式表设置QLineEdit背景透明
setStyleSheet("background-color:transparent");
纠正一下:上面这个效果好,但是有个问题,在QLineEdit上用右键菜单显示不正常
3、用样式表设置QLineEdit背景透明
setStyleSheet("background-color:rgba(212,208,200,255);");
//后面的颜色值是QWidget默认背景颜色值
(2)实现一个普通状态下为QLabel(只有文字,没有输入框)点击后变成输入框。现在的实现是组合两个对象,普通情况下显示QLabel,接收clicked信号后显示QLineEdit。但这样的实现很丑陋...如果可以设置QLineEdit为透明背景就方便了。
QLineEdit{
background:rgba(0,0,0,0%);
}