如何在自定义文件浏览对话框Qt C ++中实现后退和下一步按钮

问题描述 投票:0回答:1

我正在使用基于Qt的自定义文件打开对话框,因为本机QFileDialog会对我的应用程序造成一些阻塞。我能够实施以下内容。

  • 主页链接
  • 桌面链接
  • 父链接(向上按钮)
  • DoubleClick导航到目录

但是找不到怎么办

  • 上一个链接
  • 下一个链接

那我怎么能用Q ++在Qt5中做呢?

c++ qt user-interface qt5
1个回答
0
投票

我把它修好了

struct BrowsingHistory
{
    QString dir;
    BrowsingHistory * next;
    BrowsingHistory * prev;
    BrowsingHistory(const QString & path = "") :
        dir(path),
        next(0),
        prev(0)
    {}
};

BrowsingHistory  *m_history;
BrowsingHistory  *m_historyHead;

在构造函数中我初始化为..

m_history = m_historyHead = new BrowsingHistory(/*Your default location*/);

m_historyHead用于析构函数中的内存释放,因为它始终指向列表的开头(基本上struct BrowsingHistory是LinkedList implimentation)

while(m_historyHead)
{
    BrowsingHistory * temp = m_historyHead;
    m_historyHead = m_historyHead->next;
    delete temp;
}

m_history:总是指向当前路径。

点击桌面按钮,主页按钮,parentButton,我调用了Register History(),定义为...

void RegisterHistory(const QString& dirPath)
{
    if(m_history->dir != dirPath)
    {
        if(m_history->next)
        {
            m_history->next->dir = dirPath;
            m_history = m_history->next;
            BrowsingHistory * currentHistory = m_history->next;
            while(currentHistory)
            {
                BrowsingHistory * temp = currentHistory;
                currentHistory = currentHistory->next;
                delete temp;
            }
            m_history->next = 0;
        }
        else
        {
            BrowsingHistory * currentHistory = new BrowsingHistory(dirPath);
            currentHistory->prev = m_history;
            m_history->next = currentHistory;
            m_history = m_history->next;
        }
    }
}

现在这里是next&prev插槽:

void btnNext_Clicked()
{
    if(m_history && m_history->next)
    {
        QString dirPath = m_history->next->dir;
        ui->listFileView->setRootIndex(m_pDirModel->setRootPath(dirPath));
        m_history = m_history->next;
    }
}

void btnBack_Clicked()
{
    if(m_history && m_history->prev)
    {
        QString dirPath = m_history->prev->dir;
        ui->listFileView->setRootIndex(m_pDirModel->setRootPath(dirPath));
        m_history = m_history->prev;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.