Results 1 to 4 of 4

Thread: QTabBar paintEvent problem while porting from Qt3 to 4.

  1. #1
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default QTabBar paintEvent problem while porting from Qt3 to 4.

    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 :-

    Qt Code:
    1. void CEvTabBar::paint( QPainter *p, QTab *t, bool bSelected ) const
    2. {
    3. //QTabBar::paint( p, t, bSelected );
    4.  
    5. QStyle::State flags = QStyle::State_None;
    6.  
    7. if (isEnabled() && t->isEnabled())
    8. {
    9. flags |= QStyle::State_Enabled;
    10. }
    11. if ( bSelected )
    12. {
    13. flags |= QStyle::State_Selected;
    14. }
    15.  
    16. //selection flags
    17. if(t->rect().contains(mapFromGlobal(QCursor::pos())))
    18. {
    19. flags |= QStyle::State_MouseOver;
    20. }
    21.  
    22. style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(),
    23. colorGroup(), flags, QStyleOption(t) );
    24.  
    25. QRect r( t->rect() );
    26. p->setFont( font() );
    27.  
    28. int iw = 0;
    29. int ih = 0;
    30. if ( t->iconSet() != 0 ) {
    31. iw = t->iconSet()->pixmap( QIcon::Small, QIcon::Normal ).width() + 4;
    32. ih = t->iconSet()->pixmap( QIcon::Small, QIcon::Normal ).height();
    33. }
    34. QFontMetrics fm = p->fontMetrics();
    35. int fw = fm.width( t->text() );
    36. fw -= t->text().contains('&') * fm.width('&');
    37. fw += t->text().contains("&&") * fm.width('&');
    38. int w = iw + fw + 4;
    39. int h = QMAX(fm.height() + 4, ih );
    40. paintLabel( p, QRect( r.left() + (r.width()-w)/2 - 3,
    41. r.top() + (r.height()-h)/2,
    42. w, h ), t, t->identifier() == keyboardFocusTab() );
    43.  
    44. }
    45.  
    46.  
    47. I have replaced in Qt 4.2 with paintEvent.
    48. void CEvTabBar:: paintEvent(QPaintEvent *e)
    49. {
    50. QTabBar::paintEvent(e);
    51. --
    52. --
    53. }
    54.  
    55. Class Decln:-
    56. class CEvTabBar : public QTabBar
    To copy to clipboard, switch view to plain text mode 
    Last edited by e8johan; 30th January 2007 at 06:48. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTabBar paintEvent problem while porting from Qt3 to 4.

    What exactly do you need to do? And what does it mean that it didn't work?

  3. #3
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QTabBar paintEvent problem while porting from Qt3 to 4.

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTabBar paintEvent problem while porting from Qt3 to 4.

    Why in paintEvent? Anyway, you've got QWidget::setPalette() to do that.

Similar Threads

  1. Replies: 3
    Last Post: 27th November 2006, 09:56
  2. Problem porting Kivio MP on win32 from Qt 3 to Qt 4
    By Amanda in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2006, 19:40
  3. Problem in porting Main window on linux
    By jyoti kumar in forum Qt Tools
    Replies: 2
    Last Post: 2nd June 2006, 08:35
  4. problem of porting from windows to linux
    By jyoti kumar in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2006, 08:42
  5. Porting problem from Qt3 to Qt4
    By Krishnacins in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2006, 14:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.