Results 1 to 6 of 6

Thread: Same shape different colour

  1. #1
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Same shape different colour

    Hi All
    I have a question ,If you answer this ,i will be very appreciate.
    I want to use 5 pushbuttons on my frame with special shape (circular) by promoting . But the question is i want these button same shape but different colour. Have may i paint these buttons with different colour?I have prepared a class which is indicated in buton.h file and "paintEvent" is written in buton.cpp file. I promoted my buttons in designer by right click and "promote" -> "Buton.h". the problem is I have 5 buttons but 1 class and 1 paintEvent function. How may i paint may buttons with different colour,by using same paint event? Do i have to indicate different classes for every button?

    "buton.h file"
    Qt Code:
    1. #ifndef BUTON_H
    2. #define BUTON_H
    3. #include <QPushButton>
    4.  
    5. class buton : public QPushButton
    6. {
    7. Q_OBJECT
    8. public:
    9. buton(QWidget *event);
    10.  
    11. protected:
    12. void paintEvent(QWidget *pe);
    13. };
    14. #endif
    To copy to clipboard, switch view to plain text mode 



    "buton.cpp file"
    Qt Code:
    1. #include "buton.h"
    2.  
    3.  
    4. buton::buton(QWidget *parent=0)
    5. : QPushButton(parent)
    6. {
    7. }
    8.  
    9. void buton::paintEvent(QWidget *pe)
    10. {
    11. //May I use this place for different 5 buttons?
    12.  
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 8th February 2008 at 11:39. Reason: missing [code] tags

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

    Default Re: Same shape different colour

    Store the color as a member variable.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Same shape different colour

    can you give me an instance?

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

    Default Re: Same shape different colour

    Quote Originally Posted by anafor2004 View Post
    can you give me an instance?
    Sorry, but I'm not going to spoon feed you. Please consult your favorite C++ book. You really have to know the basics of C++ and OOP before you can start working with Qt.
    J-P Nurmi

  5. #5
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Same shape different colour

    Dear Anafor!
    You can pass colour info. with constructor and store it into a your class. After that you can applied this colour to your paint event.
    Sir JPN! has given you a right answer.
    You should play with your mind & C++ with Qt.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  6. The following user says thank you to ashukla for this useful post:

    anafor2004 (11th February 2008)

  7. #6
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Re: Same shape different colour

    thanks ashukla, I did it

Similar Threads

  1. QDockWidget splitter, cursor shape
    By alecs1 in forum Qt Programming
    Replies: 4
    Last Post: 12th December 2007, 18:44
  2. shape of a pushbutton
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 16th August 2007, 08:58
  3. Shape changing under other tab using slider/spinbox
    By kramed in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 19:59
  4. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00
  5. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44

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.