Results 1 to 12 of 12

Thread: QStyle porting problem

  1. #1
    Join Date
    Jun 2008
    Posts
    64
    Qt products
    Qt3 Qt4
    Thanks
    7

    Default QStyle porting problem

    I have the following codes in QT3
    Qt Code:
    1. QStyle::SFlags flags = QStyle::Style_Default;
    2. if ( isEnabled() )
    3. flags |= QStyle::Style_Enabled;
    4. if ( isChecked() )
    5. flags |= QStyle::Style_On;
    6. else
    7. flags |= QStyle::Style_Off;
    8. if ( isEnabled() && table()->isEnabled() )
    9. flags |= QStyle::Style_Enabled;
    10.  
    11. table()->style().drawPrimitive( QStyle::PE_Indicator, p,
    12. QRect( 0, ( cr.height() - sz.height() ) / 2, sz.width(), sz.height() ), c, flags );
    To copy to clipboard, switch view to plain text mode 
    where p is QPainter*, c is QColorGroup, cr is QRect, sz=QSize

    What should I do to convert it in QT4?

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

    Default Re: QStyle porting problem

    You have to fill (using initFrom() and setting the rect properly) and use an appropriate QStyleOption subclass.

  3. #3
    Join Date
    Jun 2008
    Posts
    64
    Qt products
    Qt3 Qt4
    Thanks
    7

    Default Re: QStyle porting problem

    I found that there's a new api which includes the QStyleOption
    But how can I set the QStyleOption ?

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

    Default Re: QStyle porting problem

    As I said, use QStyleOption::initFrom() and fill all the other needed fields manually.

  5. The following user says thank you to wysota for this useful post:

    batileon (16th July 2008)

  6. #5
    Join Date
    Jun 2008
    Posts
    64
    Qt products
    Qt3 Qt4
    Thanks
    7

    Default Re: QStyle porting problem

    QStyleOption::initFrom(QWidget*)
    What should the QWidget be????

    Sorry, I m confused.
    In the past we set the state like the code I posted, but for the QStyleOption, is that we can only obtain the values, but cannot set it?

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QStyle porting problem

    Quote Originally Posted by batileon View Post
    QStyleOption::initFrom(QWidget*)
    What should the QWidget be????
    The widget you want to init the style option for. It initializes the state, direction, rect, palette, and fontMetrics member variables based on the specified widget.

    Sorry, I m confused.
    In the past we set the state like the code I posted, but for the QStyleOption, is that we can only obtain the values, but cannot set it?
    Those "values" of QStyleOption are just public variables.
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    batileon (16th July 2008)

  9. #7
    Join Date
    Jun 2008
    Posts
    64
    Qt products
    Qt3 Qt4
    Thanks
    7

    Unhappy Re: QStyle porting problem

    For example, if I'm drawing a self-defined class which inherits Q3CheckTableItem, what should I do?
    Like this?
    Qt Code:
    1. qso->state = flags;
    2. qso->rect = QRect( 0, ( cr.height() - sz.height() ) / 2, sz.width(), sz.height() );
    3. (table()->style())->drawPrimitive( QStyle::PE_IndicatorCheckBox, qso, p );
    To copy to clipboard, switch view to plain text mode 
    What should I deal with the initFrom?
    like this?(the code is in the self defined class)
    Qt Code:
    1. qso->initFrom((QWidget *) this );
    To copy to clipboard, switch view to plain text mode 
    I tried this but this lead to segmentation fault.........

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

    Default Re: QStyle porting problem

    Q3CheckTableItem is not a widget. It's table is a widget though, so use it.

  11. #9
    Join Date
    Jun 2008
    Posts
    64
    Qt products
    Qt3 Qt4
    Thanks
    7

    Default Re: QStyle porting problem

    like this?
    Qt Code:
    1. qso->initFrom((QWidget *) table() );
    To copy to clipboard, switch view to plain text mode 

    work for compilation...... but seems still can't solve my problem.
    Actually my problem is that I found that the check box of the CheckTableItem disappeared after porting from qt3 to qt4.

    And seems this is the only change I've made.......
    Can anyone suggest where the problem is?

  12. #10
    Join Date
    Jun 2008
    Posts
    64
    Qt products
    Qt3 Qt4
    Thanks
    7

    Default Re: QStyle porting problem

    Problem solved.
    I found that the new API need a QStyleOption *
    However I found that a QStyleOptionButton * can show the checkbox but not a QStyleOption *

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

    Default Re: QStyle porting problem

    I told you to use the "appropriate QStyleOption subclass" not QStyleOption itself.

  14. #12
    Join Date
    Jun 2008
    Posts
    64
    Qt products
    Qt3 Qt4
    Thanks
    7

    Default Re: QStyle porting problem

    Thanks!!!
    I m not familiar with these stuffs........
    thank you for your support!

Similar Threads

  1. Ui problem of QT3 porting to QT4
    By batileon in forum Newbie
    Replies: 1
    Last Post: 12th June 2008, 11:31
  2. Weird problem while porting from Qt3 to Qt4
    By vermarajeev in forum Qt Programming
    Replies: 4
    Last Post: 8th August 2007, 08:51
  3. Font Problem Porting from Windows to Linux
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2007, 11:25
  4. Problem related to porting from QT3 to QT4 in list items
    By rohitjun in forum Qt Programming
    Replies: 5
    Last Post: 1st June 2007, 10:05
  5. 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, 20:40

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.