Qt 遍历文件夹#
#include <QCoreApplication>
#include <QDir>
#include <QFile>
#include <QtDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QDir dir(a.applicationDirPath());
dir.setFilter(QDir::Hidden | QDir::NoSymLinks);
QFileInfoList file_list = dir.entryInfoList(QDir::Dirs);
for(auto e: file_list){
if(e.isDir()){
QTextStream cout(stdout, QIODevice::WriteOnly);
cout << e.fileName() << Qt::endl;
}
}
return a.exec();
}
Qt 设置全局鼠标样式#
#include <QGuiApplication>
void foo(){
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
doSomething();
QGuiApplication::restoreOverrideCursor();
}
Qt/QML 带图标的按钮 (Button)#
import QtQuick.Controls 2.15
Button {
id: iconButton
height: 30
width: 30
icon.source: "qrc:///images/delete.svg"
icon.width: width
icon.height: height
icon.color: "transparent" //显示图标本身的颜色
}
Qt/QML 鼠标可以选中的输入框 (TextInput)#
import QtQuick 2.15
TextInput {
id: input
verticalAlignment: Qt.AlignVCenter
text: "请输入"
selectByMouse: true
MouseArea {
anchors.fill: parent
cursorShape: Qt.IBeamCursor
acceptedButtons: Qt.NoButton
}
}