Qt 常用函式(持續更新)
阿新 • • 發佈:2019-01-25
// 設定按鈕背景透明
set_pass_btn->setStyleSheet("background-color:transparent");
// 獲取 螢幕大小
#include"QDesktopWidget"
QDesktopWidget*desktopWidget=QApplication::desktop();
QRectdeskRect=desktopWidget->screenGeometry();
this->resize(deskRect.width(),deskRect.height());
// 去除標題欄
this->setWindowFlags(Qt::FramelessWindowHint);
#include<QPixmap>
#include<QPalette>
QScreen*screen=QGuiApplication::primaryScreen();
screen->grabWindow(0).save("bg.bmp","bmp");
QPixmappixmap("bg.bmp");
QPalettepalette;
palette.setBrush(this->backgroundRole(),QBrush(pixmap));
this->setPalette(palette);
QScreen*screen=QGuiApplication::primaryScreen();
screen->grabWindow(0).save(picName,"bmp");
//screen->grabWindow(0,x,y,wid,height).save(picName,"bmp");
/QString 字串格式化
QStringstr=QString("%1x%2").arg(wid).arg(height);
QDateTimetime=QDateTime::currentDateTime();
QStringstr=time.toString("yyyyMMddhhmmss");
QStringpicName=str+".bmp";
// 獲取程式當前目錄
#include<QDir>
#include<QMessageBox>
QStringpath;
QDirdir;
path=dir.currentPath();
QMessageBox::warning(0,"PATH",path,QMessageBox::Yes);//檢視路徑// QT開啟指定資料夾
QDesktopServices::openUrl(QUrl("file:///C:/Documents and Settings/All Users/"));
// 呼叫資原始檔例子left_bg = new QPixmap(":/res/left_bg_default.bmp");// 中文字串亂碼//將檔案編碼格式改為UTF-8
//然後重啟QT