Ignore:
Timestamp:
Jul 5, 2010, 6:29:40 PM (12 years ago)
Author:
charles
Message:

(trunk qt) #3393 "SqueezeLabel? implementation eats CPU" -- fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/squeezelabel.cc

    r10462 r10943  
    4040****************************************************************************/
    4141
     42#include <QPainter>
     43#include <QResizeEvent>
     44#include <QStyle>
     45#include <QStyleOption>
     46
    4247#include "squeezelabel.h"
    4348
    44 void
    45 SqueezeLabel::init()
     49void SqueezeLabel::init()
    4650{
    47     setTextInteractionFlags( Qt::TextSelectableByMouse );
     51    setTextInteractionFlags(Qt::TextSelectableByMouse);
    4852}
    4953
    50 SqueezeLabel::SqueezeLabel(const QString& text, QWidget *parent) : QLabel(text, parent)
     54SqueezeLabel::SqueezeLabel(const QString& text, QWidget *parent): QLabel(text, parent)
    5155{
    5256    init();
     
    5862}
    5963
    60 void SqueezeLabel::paintEvent(QPaintEvent *event)
     64void SqueezeLabel::paintEvent(QPaintEvent* paintEvent)
    6165{
     66    QPainter painter(this);
    6267    QFontMetrics fm = fontMetrics();
    63     if (fm.width(text()) > contentsRect().width()) {
    64         QString elided = fm.elidedText(text(), Qt::ElideMiddle, width());
    65         QString oldText = text();
    66         setText(elided);
    67         QLabel::paintEvent(event);
    68         setText(oldText);
    69     } else {
    70         QLabel::paintEvent(event);
    71     }
     68    QStyleOption opt;
     69    opt.initFrom(this);
     70    const QString elidedText = fm.elidedText( text(), Qt::ElideMiddle, width());
     71    style()->drawItemText(&painter, contentsRect(), alignment(), opt.palette, isEnabled(), elidedText, foregroundRole());
    7272}
    73 
Note: See TracChangeset for help on using the changeset viewer.