PDA

View Full Version : Same shape different colour



anafor2004
8th February 2008, 11:24
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"

#ifndef BUTON_H
#define BUTON_H
#include <QPushButton>

class buton : public QPushButton
{
Q_OBJECT
public:
buton(QWidget *event);

protected:
void paintEvent(QWidget *pe);
};
#endif



"buton.cpp file"

#include "buton.h"


buton::buton(QWidget *parent=0)
: QPushButton(parent)
{
}

void buton::paintEvent(QWidget *pe)
{
//May I use this place for different 5 buttons?


}

jpn
8th February 2008, 11:41
Store the color as a member variable.

anafor2004
8th February 2008, 11:49
can you give me an instance?

jpn
8th February 2008, 12:23
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.

ashukla
9th February 2008, 04:48
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.

anafor2004
11th February 2008, 10:02
thanks ashukla, I did it