qt(2)tip

1.layout
     setMargin()                 sets the width of the outer border. This is the width of the reserved space along each of the QBoxLayout's four sides. 就是设置其周围的空白距离。

     setSpacing()              sets the width between neighboring boxes. (You can use adDSPacing() to get more space at a particular spot. ) 就是设置相邻对象间的距离。

     addStretch()                to create an empty, stretchable box. 相当于加入了一个空白的不显示的部件。

2,设置窗口固定大小

      (1)setMinimumSize(370, 150); setMaximumSize(370, 150); 

      (2) setFixedSize(370,150);

3,设置背景图片

	
QPixmap _image;
   _image.load(":/images/background1.png");
   setAutoFillBackground(true);
   QPalette pal(palette());
   pal.setColor(QPalette::Background,QColor(255,0,0,100));
   pal.setBrush(QPalette::Window, QBrush(_image.scaled(size(), Qt::IgnoreAspectRatio,
                           Qt::SmoothTransformation)));
   setPalette(pal);


4,中文乱码问题

在网上找了很多,大部分都是转发的,可大部分都不可行,我的这个总结其实也是在网上查到的,但这个是真真确确可用的,经过本人亲自测试!记录于此,以备日后再用!

大部分情况下都是整个工程都是用中文的,所以直接在main函数中,定义如下:

 QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
 QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));

 

 

即可!

使用中文不需加tr()函数。

 

一下是别人的:

在程序main.cpp中加入以下代码


#include <QTextCodec>

int main(int argc, char **argv)
{
    QTextCodec *codec = QTextCodec::codecForName("GB2312");
    QTextCodec::setCodecForLocale(codec);

    QTextCodec::setCodecForCStrings(codec);

    QTextCodec::setCodecForTr(codec);
}
这样在程序其他地方就可以使用中文了, tr(“中文”) 或者直接使用“中文了;


解决读取ini文件中中文乱码

QSettings settings("xxxx.ini",QSettings::IniFormat);

settings.setIniCodec(QTextCodec::codecForName("GB2312"));   //在此添加设置,即可读写ini文件中的中文

settings.beginGroup("company");

 

解决读取中文文件中文的乱码
QFile file("xxxx.txt");
QTextStream stream(file,QIODevice::ReadOnly);
stream.setCodeC( QTextCodec::codecForName("GB2312") );
stream.readAll();



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值