Results 1 to 2 of 2

Thread: Assigning new QStyle

  1. #1
    Join Date
    May 2011
    Posts
    27
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Assigning new QStyle

    Hello everyone,
    I want to create my own Style, so I created a class which inherits QStyle. This class does till now nothing

    Qt Code:
    1. //MyStyleClass.h
    2. class MyStyle : public QStyle
    3. {
    4. Q_OBJECT
    5. public:
    6. MyStyle();
    7.  
    8. void polish(QPalette &palette);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //MyStyleClass.cpp
    2. MyStyle::MyStyle()
    3. {
    4. }
    5.  
    6. void MyStyle::polish(QPalette &palette)
    7. {
    8. }
    To copy to clipboard, switch view to plain text mode 

    My test programm is just a dialog box with a button assigned. But how can I assign the new Style to my programm?
    I tried it out in the main() function via:
    Qt Code:
    1. QApplication::setStyle(new MyStyle);
    To copy to clipboard, switch view to plain text mode 
    but I just get an error from the compiler which says:
    cannot allocate an object of abstract type 'MyStyle'
    because the following virtual functions are pure within 'MyStyle':
    virtual void QStyle::drawPrimitive(QStyle::PrimitiveElements, const QStyleOption*, QPainter*, const Qwidget*) const;

    and a lot more functions

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Assigning new QStyle

    That's quite an obvious error. Your implementation of QStyle is incomplete. There is bunch of pure virtual functions in QStyle that you must implement. Try subclassing already existing, fully implemented style, it will be easier. QMotifStyle or whatever other style you like.
    Don't write a post just to thank someone, use "Thanks" button.

  3. The following user says thank you to Rachol for this useful post:

    seux (29th August 2011)

Similar Threads

  1. Replies: 2
    Last Post: 14th July 2011, 12:28
  2. Qt Creator Assigning different compiler
    By hibbity in forum Qt Tools
    Replies: 8
    Last Post: 24th May 2011, 17:45
  3. question about assigning a pixmap to an icon
    By Dark_Tower in forum Newbie
    Replies: 5
    Last Post: 21st December 2009, 09:11
  4. Replies: 1
    Last Post: 1st June 2009, 20:58
  5. Assigning QActions without a QMenuBar nor toolbars
    By elcuco in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2008, 18:35

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.