[Qt-interest] Animated QProgressBar in a QTableView
Brad Howes
howes at ll.mit.edu
Thu Sep 2 16:34:02 CEST 2010
On Sep 1, 2010, at 6:54 PM, Omar AKHAM wrote:
> Hi,
>
> In QtDesigner, putting a QProgressBar and setting it's min = max = 0, the result is an animated QProgressBar (look like a WaitingBar without progression). How to have it in a QTableView (using a custom delegate) ? I tried to do it, but the ProgressBar is not animated.
Are you emitting the dataChanged() signal from you model so that your row updates and calls your delegate? I've added a simple loading progress bar to a playback utility that works fine, but I just do a QPainter::fill() in the row's rectangle to show the percentage loaded:
void
NameItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
const FileModel* model = static_cast<const FileModel*>( index.model() );
const Emitter* emitter = model->getEmitter( index.row() );
double loadPercentage = emitter->getLoadPercentage();
if ( loadPercentage ) {
QRect rect = option.rect;
rect.setWidth( rect.width() * loadPercentage );
painter->fillRect( rect, option.palette.highlight() );
}
Super::paint( painter, option, index );
}
The loading happens in separate threads (one for each playback channel). The loading thread periodically emits a signal to indicate progress, which ultimate results in the model's dataChanged() signal firing causing the row associated with the loader to redisplay.
Brad
--
Brad Howes
Group 42
MIT Lincoln Laboratory • 244 Wood St. • Lexington, MA 02173
Phone: 781.981.5292 • Fax: 781.981.3495 • Secretary: 781.981.7420
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100902/a221bf5c/attachment.html
More information about the Qt-interest-old
mailing list