QT4模块二 《常用代码》

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);

  

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值