如何将QProgressBar放在QTextEdit中

时间:2019-03-22 19:57:31

标签: c++ c++11 qt5 qtextedit qprogressbar

我正在使用QTextEdit设计一个command log,我想知道如何在每次用户与用户界面交互且仅针对特定命令的情况下放置QProgressBar 。例如,如果用户上传的图像应该比QProgressBar多,则如果用户仅设置一些控件,则没有必要。到目前为止,我还没有发现任何可以描述这一点的东西。

progress bar

例如,我将下面的代码片段放在QProgressBar的下面(例如,用户在QGraphicsView上上传图像并显示加载百分比进度):

mainwindow.cpp

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    mDockWidget_A = new QDockWidget(QLatin1String("Command Log"));
    mDockWidget_A->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    mDockWidget_A->setMinimumHeight(30);
    // Adding object to the DockWidget
    mNewText = new QTextEdit;
    mNewText->setReadOnly(true);
    mNewText->setStyleSheet("background-color: light grey;");
    mNewText->setMinimumHeight(50);
    mNewText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    mDockWidget_A->setWidget(mNewText);
    addDockWidget(Qt::BottomDockWidgetArea, mDockWidget_A);
    resizeDocks({mDockWidget_A}, {200}, Qt::Horizontal);

}

void MainWindow::on_originalmgA_clicked()
{
    imageOriginlUploadA();
    QSize s{32, 32};
    QTextDocumentFragment fragment;
    fragment = QTextDocumentFragment::fromHtml(
                QString(R"(<img src='/home/path/toDesktop/working.png' height="%1" width="%2">)")
                .arg(s.width())
                .arg(s.height()));
    mNewText->textCursor().insertFragment(fragment);
    mNewText->append("\n");
    mNewText->setVisible(true);
}

void MainWindow::imageOriginlUploadB()
{
    dir_Original_B = QFileDialog::getExistingDirectory(this, tr("Choose an image directory to load"),
                                                     filesListRight, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
    if(dir_Original_B.length() > 0){
        QImage image;
        QDir dirBObj(dir_Original_B);
        QStringList filesListRight = dirBObj.entryList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden  | QDir::AllDirs | QDir::Files, QDir::DirsFirst);
        ui->labelOrigImageB->setPixmap(QPixmap::fromImage(image.scaled(125,125,Qt::KeepAspectRatio,Qt::SmoothTransformation)));
        for ( int i = 0 ; i < filesListRight.size() ; i++ )
        {
            ui->listWidgetOriginalImgB->addItem(filesListRight.at(i));
        }
        ui->listWidgetOriginalImgB->update();
        ui->labelOrigImageB->show();
    }
}

是否可以在QProgressBar内插入QTextEdit?如果是的话,有人可以指出任何有用的方向或提供有关此问题的示例吗?

0 个答案:

没有答案