qt(2)tip
来源:互联网 发布:cnc编程入门教程 编辑:程序博客网 时间:2024/05/29 18:22
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();
- qt(2)tip
- Qt 的tool tip
- Qt tip 数据库 sqlite
- Qt学习之路(tip): parent参数
- Qt学习之路(tip): parent参数
- Qt学习之路(tip): parent参数
- Qt 学习之路(tip): parent 参数
- Qt学习之路(tip): parent参数
- Qt学习之路(tip): parent参数
- Java Tip(2)
- tip
- Tip
- tip
- Tip:
- TIP
- Tip
- tip
- Tip
- Deep learning------------Visualizing Higher Layer Features of a Deep Network.
- 在Linux下安装MySql 5.6.14
- 数理统计知识回顾
- 网络编程书籍推荐
- ARM汇编与C语言对照
- qt(2)tip
- 使用Xcode修改iOS项目工程名和路径名
- string方法:将s1,s2连接起来保存在s1中
- MYSQL 测试
- 修改 vi 中 comment 的显示颜色
- 在Eclipse中使用JUnit4进行单元测试(中级篇)
- HTML颜色设置
- 【运维】映射网络驱动器选项
- 银行系统