PDA

View Full Version : QTabBar paintEvent problem while porting from Qt3 to 4.



user_mail07
30th January 2007, 00: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

wysota
30th January 2007, 09:07
What exactly do you need to do? And what does it mean that it didn't work?

user_mail07
2nd February 2007, 19:02
actually i want to paint the backgound of my application. Now it is diplaying default QPalette::Window general color. Is there any way that I can change QPalette: window default color to desired color in paintEvent. Because after porting to qt4 backgorund color is not showing up.

wysota
2nd February 2007, 22:18
Why in paintEvent? Anyway, you've got QWidget::setPalette() to do that.