本文整理汇总了C++中QProgressBar::sizeHint方法的典型用法代码示例。如果您正苦于以下问题:C++ QProgressBar::sizeHint方法的具体用法?C++ QProgressBar::sizeHint怎么用?C++ QProgressBar::sizeHint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProgressBar
的用法示例。
在下文中一共展示了QProgressBar::sizeHint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillPartialArchiveItem
void ArchiveList::fillPartialArchiveItem(PartialArchive *a, QTreeWidgetItem *item)
{
QTreeWidgetItem *subItem = new QTreeWidgetItem(item);
QPushButton *pauseButton = new QPushButton();
pauseButton->setText(a->isDownloading() ? tr("Pause") : tr("Continue"));
connect(pauseButton, SIGNAL(clicked()), a, SLOT(togglePauseDownload()));
downloadPausedMapper->setMapping(a, pauseButton);
downloadStartedMapper->setMapping(a, pauseButton);
connect(a, SIGNAL(downloadStarted()), downloadStartedMapper, SLOT(map()));
connect(a, SIGNAL(downloadPaused()), downloadPausedMapper, SLOT(map()));
int pbarColumn;
if (compactLayout) {
pbarColumn = 1;
subItem->setSizeHint(1, pauseButton->sizeHint());
setItemWidget(subItem, 1, pauseButton);
QPushButton *detailsButton = new QPushButton(tr("Details"));
showDetailsMapper->setMapping(detailsButton, a);
connect(detailsButton, SIGNAL(clicked()), showDetailsMapper, SLOT(map()));
subItem->setSizeHint(0, detailsButton->sizeHint());
setItemWidget(subItem, 0, detailsButton);
} else {
pbarColumn = 2;
item->setSizeHint(3, pauseButton->sizeHint());
setItemWidget(item, 3, pauseButton);
item->setText(1, a->getSizeMB());
QLabel *peerInfo = new QLabel();
subItem->setSizeHint(1, peerInfo->sizeHint());
setItemWidget(subItem, 1, peerInfo);
connect(a, SIGNAL(peerInfoUpdated(QString)), peerInfo, SLOT(setText(QString)));
QLabel *speedText = new QLabel();
subItem->setSizeHint(2, speedText->sizeHint());
setItemWidget(subItem, 2, speedText);
connect(a, SIGNAL(speedTextUpdated(QString)), speedText, SLOT(setText(QString)));
QLabel *statusText = new QLabel();
subItem->setSizeHint(3, statusText->sizeHint());
setItemWidget(subItem, 3, statusText);
connect(a, SIGNAL(statusTextUpdated(QString)), statusText, SLOT(setText(QString)));
}
QProgressBar *pbar = new QProgressBar();
pbar->setMinimum(0);
pbar->setMaximum(100);
item->setSizeHint(pbarColumn, pbar->sizeHint());
setItemWidget(item, pbarColumn, pbar);
connect(a, SIGNAL(progressUpdated(int)), pbar, SLOT(setValue(int)));
a->emitStatusEvents();
}
示例2: updateItemWidgets
void ProgressListDelegate::updateItemWidgets(const QList<QWidget*> widgets,
const QStyleOptionViewItem &option,
const QPersistentModelIndex &index) const
{
if (!index.isValid()) {
return;
}
QPushButton *pauseResumeButton = static_cast<QPushButton*>(widgets[0]);
QPushButton *cancelButton = static_cast<QPushButton*>(widgets[1]);
cancelButton->setToolTip(i18n("Cancel"));
QProgressBar *progressBar = static_cast<QProgressBar*>(widgets[2]);
QPushButton *clearButton = static_cast<QPushButton*>(widgets[3]);
int percent = d->getPercent(index);
cancelButton->setVisible(percent < 100);
pauseResumeButton->setVisible(percent < 100);
clearButton->setVisible(percent > 99);
KJob::Capabilities capabilities = (KJob::Capabilities) index.model()->data(index, JobView::Capabilities).toInt();
cancelButton->setEnabled(capabilities & KJob::Killable);
pauseResumeButton->setEnabled(capabilities & KJob::Suspendable);
JobView::JobState state = (JobView::JobState) index.model()->data(index, JobView::State).toInt();
switch (state) {
case JobView::Running:
pauseResumeButton->setToolTip(i18n("Pause"));
pauseResumeButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-pause")));
break;
case JobView::Suspended:
pauseResumeButton->setToolTip(i18n("Resume"));
pauseResumeButton->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start")));
break;
default:
Q_ASSERT(0);
break;
}
QSize progressBarButtonSizeHint;
if (percent < 100) {
QSize cancelButtonSizeHint = cancelButton->sizeHint();
cancelButton->move(option.rect.width() - d->separatorPixels - cancelButtonSizeHint.width(),
option.rect.height() - d->separatorPixels - cancelButtonSizeHint.height());
QSize pauseResumeButtonSizeHint = pauseResumeButton->sizeHint();
pauseResumeButton->move(option.rect.width() - d->separatorPixels * 2 - pauseResumeButtonSizeHint.width() - cancelButtonSizeHint.width(),
option.rect.height() - d->separatorPixels - pauseResumeButtonSizeHint.height());
progressBarButtonSizeHint = pauseResumeButtonSizeHint;
} else {
progressBarButtonSizeHint = clearButton->sizeHint();
clearButton->resize(progressBarButtonSizeHint);
clearButton->move(option.rect.width() - d->separatorPixels - progressBarButtonSizeHint.width(),
option.rect.height() - d->separatorPixels - progressBarButtonSizeHint.height());
}
progressBar->setValue(percent);
QFontMetrics fm(QApplication::font());
QSize progressBarSizeHint = progressBar->sizeHint();
progressBar->resize(QSize(option.rect.width() - d->getCurrentLeftMargin(fm.height()) - d->rightMargin, progressBarSizeHint.height()));
progressBar->move(d->getCurrentLeftMargin(fm.height()),
option.rect.height() - d->separatorPixels * 2 - progressBarButtonSizeHint.height() - progressBarSizeHint.height());
}