user_mail07
29th January 2007, 23:49
QTabBar paintEvent problem while porting from Qt3 to 4.
In qt 3 there was a QTabBar paint function QTabBar paint ( QPainter * p, QTab * t, bool selected ) const [virtual protected]. I have replaced with to paintEvent in Qt4. However I am not able to get similar functionality at all. Even we were not using any custom painting in our code using Qt 3. We simply used source code of paint function of QTabBar class in Qt3 . SO i tried to copy with Qt 4 source code but still did not work.
Here the code snippet for paint function that we used for Qt 3 :-
void CEvTabBar::paint( QPainter *p, QTab *t, bool bSelected ) const
{
//QTabBar::paint( p, t, bSelected );
QStyle::State flags = QStyle::State_None;
if (isEnabled() && t->isEnabled())
{
flags |= QStyle::State_Enabled;
}
if ( bSelected )
{
flags |= QStyle::State_Selected;
}
//selection flags
if(t->rect().contains(mapFromGlobal(QCursor::pos())))
{
flags |= QStyle::State_MouseOver;
}
style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(),
colorGroup(), flags, QStyleOption(t) );
QRect r( t->rect() );
p->setFont( font() );
int iw = 0;
int ih = 0;
if ( t->iconSet() != 0 ) {
iw = t->iconSet()->pixmap( QIcon::Small, QIcon::Normal ).width() + 4;
ih = t->iconSet()->pixmap( QIcon::Small, QIcon::Normal ).height();
}
QFontMetrics fm = p->fontMetrics();
int fw = fm.width( t->text() );
fw -= t->text().contains('&') * fm.width('&');
fw += t->text().contains("&&") * fm.width('&');
int w = iw + fw + 4;
int h = QMAX(fm.height() + 4, ih );
paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3,
r.top() + (r.height()-h)/2,
w, h ), t, t->identifier() == keyboardFocusTab() );
}
I have replaced in Qt 4.2 with paintEvent.
void CEvTabBar:: paintEvent(QPaintEvent *e)
{
QTabBar::paintEvent(e);
--
--
}
Class Decln:-
class CEvTabBar : public QTabBar
In qt 3 there was a QTabBar paint function QTabBar paint ( QPainter * p, QTab * t, bool selected ) const [virtual protected]. I have replaced with to paintEvent in Qt4. However I am not able to get similar functionality at all. Even we were not using any custom painting in our code using Qt 3. We simply used source code of paint function of QTabBar class in Qt3 . SO i tried to copy with Qt 4 source code but still did not work.
Here the code snippet for paint function that we used for Qt 3 :-
void CEvTabBar::paint( QPainter *p, QTab *t, bool bSelected ) const
{
//QTabBar::paint( p, t, bSelected );
QStyle::State flags = QStyle::State_None;
if (isEnabled() && t->isEnabled())
{
flags |= QStyle::State_Enabled;
}
if ( bSelected )
{
flags |= QStyle::State_Selected;
}
//selection flags
if(t->rect().contains(mapFromGlobal(QCursor::pos())))
{
flags |= QStyle::State_MouseOver;
}
style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(),
colorGroup(), flags, QStyleOption(t) );
QRect r( t->rect() );
p->setFont( font() );
int iw = 0;
int ih = 0;
if ( t->iconSet() != 0 ) {
iw = t->iconSet()->pixmap( QIcon::Small, QIcon::Normal ).width() + 4;
ih = t->iconSet()->pixmap( QIcon::Small, QIcon::Normal ).height();
}
QFontMetrics fm = p->fontMetrics();
int fw = fm.width( t->text() );
fw -= t->text().contains('&') * fm.width('&');
fw += t->text().contains("&&") * fm.width('&');
int w = iw + fw + 4;
int h = QMAX(fm.height() + 4, ih );
paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3,
r.top() + (r.height()-h)/2,
w, h ), t, t->identifier() == keyboardFocusTab() );
}
I have replaced in Qt 4.2 with paintEvent.
void CEvTabBar:: paintEvent(QPaintEvent *e)
{
QTabBar::paintEvent(e);
--
--
}
Class Decln:-
class CEvTabBar : public QTabBar