数据类型和数据操作类
比较和判断变量的函数
函数 | 作用 |
---|---|
qAbs(const T& value) | 返回绝对值 |
qBound(min,mid,max) | 返回mid |
qMax() | |
qMIn() | |
qRound() | 四舍五入 |
数据类
QBitArray:
/*
* count()数组的长度,size
* fill(bool,start,end)填充数组
* resize(int)重置长度
* clear()长度变为0
* clearBit(int)让int位置的值变成0
* isEmpty()当count=0时,为true
* 可以参与&|!名算
*
*/
MyFileSystem::MyFileSystem(QWidget *parent)
:QWidget(parent)
{
QBitArray a1(5);//a1=[0 0 0 0 0]
qDebug()<<"数组的长度"<<a1.count()<<a1;
a1.fill(true,0,a1.count());//a1=[1 1 1 1 1]
qDebug()<<"fill之后的变化"<<a1;
a1.resize(3);
qDebug()<<a1.count()<<a1;
a1.clearBit(0);
qDebug()<<a1.count()<<a1<<a1.isEmpty();
}
QBrush:
void MyFileSystem::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QRadialGradient gradient(50, 50, 50, 50, 50);
gradient.setColorAt(0, QColor::fromRgbF(0, 1, 0, 1));
gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0));
QBrush brush(gradient);
painter.setBrush(brush);
painter.setPen(Qt::darkCyan);
painter.drawRect(0,0,100,100);
painter.setBrush(Qt::NoBrush);
painter.setPen(Qt::darkGreen);
painter.drawRect(40,40,100,100);
}
QByteArray
MyFileSystem::MyFileSystem(QWidget *parent)
:QWidget(parent)
{
//1.构造
QByteArray a1(5,'x'); //a1=[x x x x x] size=5
QByteArray a2("hello the world"); //a2="hello the word" size=15
QByteArray a3(a2); //a3=a2
//2.增删查改大小
a3.append(a1); //a3=hello the worldxxxxx
a3.clear();
a3.append(5,'a');
a3.append("zylg"); //a3=aaaaazylg
a3.clear();
a3.insert(0,"zylg");
a3.insert(0,3,'x');
a3.insert(7,a1); //a3=xxxzylgxxxxx"
a3.push_back("zy"); ////a3=xxxzylgxxxxxzy"
a3.push_front("zy"); //a3=zyxxxzylgxxxxxzy"
a3.replace("xxx",""); //a3=zyzylgxxzy
a3.replace(0,2,"zylg"); //a3=zylgzylgxxzy
a3.remove(2,3); //a3=zyylgxxzy"
qDebug()<<a3<<a3.capacity()<<a3.length();
//3.位置
a3.clear();
a3.append("zylgzy");
a3.at(1); //return y
qDebug()<<a3.indexOf("zy",3); //从三个开始算,zy的位置在哪,4
qDebug()<<a3.lastIndexOf("zy");
qDebug()<<a3.left(4); //zylg
qDebug()<<a3.right(4); //lgzy
//4.其他(转换,包换,截取 )
for(auto it=a3.begin();it!=a3.end();it++) //迭代器
{
qDebug()<<*it;
}
if(a3.contains("zy"))qDebug()<<"contains"; //包含zy
qDebug()<<a3.count("zy"); //zy的个数
char *data=a3.data(); //a3的数据
qDebug()<<data;
if(a3.endsWith("zy"))qDebug()<<"结尾包含zy";//以zy结尾
if(a3.startsWith("zy"))qDebug()<<"以zy开头";
a3.setNum(43,16); //添加43的十六进制,a3=2b
QByteArray ba(" lots\t of\nwhitespace\r\n ");
ba = ba.simplified(); // ba == "lots of whitespace";
// a3.resize(20);a3.fill('x',10); //a3=xxxxxxxxxx
qDebug()<<a3;
//toHex() 大小写 toInt toFloat等 rePeat
}
QColor
QColor color(r,g,b,255)
QData
QDate data=QDate::currentDate();
QDateTime da=QDateTime::currentDateTime();
QEasingCurve
QPropertyAnimation animation;
animation.setStartValue(0);
animation.setEndValue(1000);
animation.setDuration(1000);
animation.setEasingCurve(QEasingCurve::InOutQuad);
QKeySequence
QKeySequence(QKeySequence::Print);
QKeySequence(tr("Ctrl+P"));
QKeySequence(tr("Ctrl+p"));
QKeySequence(Qt::CTRL + Qt::Key_P)
QMenu *file = new QMenu(this);
file->addAction(tr("&Open..."), this, SLOT(open()),
QKeySequence(tr("Ctrl+O", "File|Open")));
QUrl
QUrl url("http://www.example.com/List of holidays.xml");
// url.toEncoded() == "http://www.example.com/List%20of%20holidays.xml"
QUrl url = QUrl::fromEncoded("http://qt-project.org/List%20of%20holidays.xml");