void TabWidget::paintEvent( QPaintEvent * _pe ) { setFont( pointSize<8>( font() ) ); QPainter p( this ); QColor bg_color = QApplication::palette().color( QPalette::Active, QPalette::Background ); QLinearGradient g( 0, 0, 0, m_tabheight ); g.setColorAt( 0, bg_color.darker( 250 ) ); g.setColorAt( 0.1, bg_color.lighter( 120 ) ); g.setColorAt( 1, bg_color.darker( 250 ) ); p.fillRect( 0, 0, width() - 1, height() - 1, bg_color ); bool big_tab_captions = ( m_caption == "" ); p.setPen( bg_color.darker( 150 ) ); p.drawRect( 0, 0, width() - 1, height() - 1 ); p.setPen( bg_color.light( 150 ) ); p.drawLine( width() - 1, 0, width() - 1, height() - 1 ); p.drawLine( 0, height() - 1, width() - 1, height() - 1 ); p.setPen( QColor( 0, 0, 0 ) ); p.drawRect( 1, 1, width() - 3, height() - 3 ); p.fillRect( 2, 2, width() - 4, m_tabheight, g ); p.drawLine( 2, m_tabheight + 2, width() - 3, m_tabheight + 2); if( ! m_caption.isEmpty() ) { p.setPen( QColor( 255, 255, 255 ) ); p.drawText( 5, 11, m_caption ); } // Calculate the tabs' x (tabs are painted next to the caption) int tab_x_offset = m_caption.isEmpty() ? 4 : 14 + fontMetrics().width( m_caption ); QColor cap_col( 160, 160, 160 ); if( big_tab_captions ) { p.setFont( pointSize<8>( p.font() ) ); cap_col = QColor( 224, 224, 224 ); } else { p.setFont( pointSize<7>( p.font() ) ); } p.setPen( cap_col ); for( widgetStack::iterator it = m_widgets.begin(); it != m_widgets.end(); ++it ) { if( it.key() == m_activeTab ) { p.setPen( QColor( 32, 48, 64 ) ); p.fillRect( tab_x_offset, 2, ( *it ).nwidth - 6, 10, cap_col ); } p.drawText( tab_x_offset + 3, m_tabheight, ( *it ).name ); p.setPen( cap_col ); tab_x_offset += ( *it ).nwidth; } }
void tabWidget::paintEvent( QPaintEvent * _pe ) { setFont( pointSize<7>( font() ) ); QPainter p( this ); QColor bg_color = QApplication::palette().color( QPalette::Active, QPalette::Background ); QLinearGradient g( 0, 0, 0, 10 ); g.setColorAt( 0, bg_color.darker( 250 ) ); g.setColorAt( 0.1, bg_color.lighter( 120 ) ); g.setColorAt( 1, bg_color.darker( 250 ) ); p.fillRect( 0, 0, width() - 1, height() - 1, bg_color ); bool big_tab_captions = ( m_caption == "" ); int add = big_tab_captions ? 1 : 0; p.setPen( bg_color.darker( 150 ) ); p.drawRect( 0, 0, width() - 1, height() - 1 ); p.setPen( bg_color.light( 150 ) ); p.drawLine( width() - 1, 0, width() - 1, height() - 1 ); p.drawLine( 0, height() - 1, width() - 1, height() - 1 ); p.setPen( QColor( 0, 0, 0 ) ); p.drawRect( 1, 1, width() - 3, height() - 3 ); p.fillRect( 2, 2, width() - 4, 9 + add, g ); p.drawLine( 2, 11 + add, width() - 3, 11 + add ); if( !big_tab_captions ) { p.setPen( QColor( 255, 255, 255 ) ); p.drawText( 5, 10, m_caption ); } int cx = ( big_tab_captions ? 4 : 14 ) + fontMetrics().width( m_caption ); QColor cap_col( 160, 160, 160 ); if( big_tab_captions ) { p.setFont( pointSize<7>( p.font() ) ); cap_col = QColor( 224, 224, 224 ); } else { p.setFont( pointSize<6>( p.font() ) ); } p.setPen( cap_col ); for( widgetStack::iterator it = m_widgets.begin(); it != m_widgets.end(); ++it ) { if( it.key() == m_activeTab ) { p.setPen( QColor( 32, 48, 64 ) ); p.fillRect( cx, 2, ( *it ).nwidth - 6, 9, cap_col ); } p.drawText( cx + 3, 9 + add, ( *it ).name ); p.setPen( cap_col ); cx += ( *it ).nwidth; } }