[QT Network Cloud Disk Client]——Implementing file properties window

Table of contents

File Properties Dialog

Set font style

 Get file information

Show file properties dialog

When we click on the properties in the file, a properties dialog box will pop up: 

 

Implementation process:

0. Set the slot function of the property menu item .

1. The mouse gets the QListWidgetItem selected by the mouse , which contains the icon and file name.

2. Find the corresponding FileInfo object according to the file name

ps: FileInfo is a file information object. In the process of displaying the file list, the file information of each file has been saved to QList<FileInfo*> m_fileInfoList

3. Set the information in the FileInfo object into the file properties dialog box. 

File Properties Dialog

 Implementation process:

Customize a filePropertyiInfoDialog type and inherit the QDialog type, including

filePropertyiInfoDialog.h, filePropertyiInfoDialog.cpp ,filePropertyiInfoDialog.ui文件

filePropertyiInfoDialog.ui interface design:

 

Set font style

 filePropertyiInfoDialog.cpp, set the font color in the constructor:

filePropertyiInfoDialog::filePropertyiInfoDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::filePropertyiInfoDialog)
{
    ui->setupUi(this);
    QString style1 = QString("color: rgb(11, 11, 11);font: 75 14pt \"Agency FB\";");
    QString style2 = QString("font: 14pt \"隶书\";color: rgb(255, 156, 16);");

    this->setWindowTitle("文件属性");
    ui->lbl_fileName->setStyleSheet(style1);
    ui->lbl_fileSize->setStyleSheet(style1);
    ui->lbl_download->setStyleSheet(style1);
    ui->lbl_shareStatus->setStyleSheet(style1);
    ui->lbl_uploadTime->setStyleSheet(style1);
    ui->lbl_uploadUser->setStyleSheet(style1);

    ui->val_fileName->setStyleSheet(style2);
    ui->val_fileSize->setStyleSheet(style2);
    ui->val_download->setStyleSheet(style2);
    ui->val_shareStatus->setStyleSheet(style2);
    ui->val_uploadTime->setStyleSheet(style2);
    ui->val_uploadUser->setStyleSheet(style2);

}

 Get file information

    //设置属性菜单项的槽函数
    connect(m_propertyAction,&QAction::triggered,this,[=]{
        dealfile(DealFile::Show);
    });


void myfile::dealfile(DealFile cmd)
{
    //获取鼠标选中的QListWidgetItem
    QListWidgetItem* item=ui->listWidget->currentItem();

    for(int i=0;i<m_fileInfoList.length();i++)
    {
        //根据文件名找到对应的文件信息
        FileInfo* fileInfo=m_fileInfoList[i];
        if(fileInfo->fileName==item->text())
        {

           if(cmd==DealFile::Show)
            {
                //显示文件属性
                showFileProperty(fileInfo);
            }
        }
    }
}

Show file properties dialog


//fileinfo.h文件
struct FileInfo
{
    QString user;           //用户名
    QString md5;            //md5
    QString createTime;     //上传时间
    QString fileName;       //文件名称
    int shareStatus;        //共享状态, 0为没有共享, 1为共享
    int pv;                 //文件下载量,下载一次加1
    QString url;            //文件url
    int size;               //文件大小
    QString type;           //文件类型
};


//filePropertyiInfoDialog.cpp文件
//显示filePropertyiInfoDialog文件属性对话框
void myfile::showFileProperty(FileInfo *fileInfo)
{
    //弹出对话框,显示文件属性
    filePropertyiInfoDialog* dialog=new filePropertyiInfoDialog();
    dialog->setFileInfo(fileInfo);
    dialog->show();
}

//将fileInfo的信息设置到filePropertyiInfoDialog中
void filePropertyiInfoDialog::setFileInfo(FileInfo *fileInfo)
{
    //设置文件名称
    ui->val_fileName->setText(fileInfo->fileName);

    int size=fileInfo->size;
    QString fileSize;
    //设置文件大小
    if(size<1024){
          fileSize=QString("%1字节").arg(QString::number(size));
    }
    else if(size>=1024)
    {
         fileSize=QString("%1 kb").arg(QString::number(size/1024));
    }
    else if(size>=1024*1024)
    {
          fileSize=QString("%1 kb").arg(QString::number(size/(1024*1024)));
    }
    
    ui->val_fileSize->setText(fileSize);
    //设置文件的url
    ui->val_download->setText(fileInfo->url);
    //设置文件的分享状态
    ui->val_shareStatus->setText(QString::number(fileInfo->shareStatus));
    //设置文件的上传时间
    ui->val_uploadTime->setText(fileInfo->createTime);
    //设置文件的使用者
    ui->val_uploadUser->setText(fileInfo->user);
}

Guess you like

Origin blog.csdn.net/sjp11/article/details/131971858
Recommended