1、如果LineEdit的输入要求以密码形式进行输入
lineEdit->setEchoMode(QLineEdit::Password);
若要以"*"号形式进行显示的话则设置stylesheet
lineEdit->setStyleSheet("lineedit-password-character: 42");
2、设置背景图片
setAutoFillBackground(true);
Qpalette plt;
QPixmap pixmap(":/images/background.jpg");
plt.setBrush(backgroundRole(),QBrush(pixmap));
setPalette(plt);
3、设置窗体居中显示(在显示屏的中间)
int x = (QApplication::desktop()->width() - this->width()) / 2;
int y = (QApplication::desktop()->height() - this->height())/2;
move(x,y);
4、设置窗口图标及标题
setWindowTitle("窗口名");
setWindowIcon(QIcon("图片"));
5、Sql结合QT正则表达式进行ID模糊查询的使用
QString str = "查询的内容";
QRegExp rx;
rx.setPatternSyntax(QRegExp::RegExp);
rx.setPattern(QString("^[0-9]+$")); //所有以数字组成的字符串格式
if(rx.exactMatch(str))
{
model->setFilter(QString::fromLocal8Bit("ID like '%1' ").arg(QString("%")+=str+=QString("%")));
model->select();
}
6、在QTableWidget 中显示图片并且设置表格行列大小
QTableWidget *table = new QTableWidget(this);
table->setRowCount(4);
table->setColumnCount(2);
int j;
for(j=0;j<2;j++)
table->setColumnWidth(j,300);
for(j=0;j<6;j++)
table->setRowWidth(j,200);
QLabel *label = new QLabel;
label->setPixmap(QPixmap(":/images/1.png"));
label->setScaledContents(true);
table->setCellWidget(1,1,label);