How I make my own button?
my class of a button, whit diferent style, shape, and actions?
(I tried to make an special color button)
Thanks
Printable View
How I make my own button?
my class of a button, whit diferent style, shape, and actions?
(I tried to make an special color button)
Thanks
Quote:
Originally Posted by avis_phoenix
Subclass QPushButton or QAbstractButton.Quote:
shape, and actions?
Subclass QStyle or one of its subclasses.Quote:
whit diferent style
If you just want to change colours, maybe it will be enough if you modify its QWidget::palette() using QWidget::setPalette().Quote:
(I tried to make an special color button)
I tried to make this class
Code:
After i tried use this class with:
Code:
1 QVector<ColorButton> Button(32); 2 for (i =0; i< 4;i++) 3 { 4 for (int j = 0; j < 8;j++) 5 Button[i] = ColorButton(this,x+(i*21),y+(j*21),21,21); //intent for define each button }
But gcc say:
cannot allocate and object of type 'ColorButton' in the line 5
because the following virtual functions are abstracts
then how make the class type abstractsbuttons to create a new button?
Sorry for my bad english
You must implement all abstract methods (the compiler should tell you which ones are missing).Quote:
Originally Posted by avis_phoenix
Also, you must create your buttons on the heap not the stack. As is, your code will not work as your buttons will instantly go out of scope. Try:
Code:
QVector<ColorButton*> Button(32); for (i =0; i< 4;i++) { for (int j = 0; j < 8;j++) Button[i] = new ColorButton(this,x+(i*21),y+(j*21),21,21); }
Also you can't copy widgets.Quote:
Originally Posted by Chicken Blood Machine
Well i implement the abstracts metods and now gcc don't say
"cannot allocate and object of type 'ColorButton' in the line 5
because the following virtual functions are abstracts"
but say :
In copy constructor `ColorButton::ColorButton(const ColorButton&)':
D:/Qt/4.1.2/include/QtGui/../../src/gui/widgets/qabstractbutton.h:139:
error: `QAbstractButton::QAbstractButton(const QAbstractButton&)' is private
error: within this context
In member function `ColorButton& ColorButton::operator=(const ColorButton&)':
D:/Qt/4.1.2/include/QtGui/../../src/gui/widgets/qabstractbutton.h:139:
error: `QAbstractButton& QAbstractButton::operator=(const QAbstractButton&)' is private
error: within this context
in the line
Button[i] = ColorButton(this,x+(i*21),y+(j*21),21,21);
don´t work if i put Button[i] = new ColorButton(this,x+(i*21),y+(j*21),21,21);
Help me please
Chicken Blood Machine and jacek already gave you the solution.
You cannot copy widgets, so you cannot store them into QVector as objects. Store pointers instead.
You have to change the type of the vector from QVector<ColorButton> to QVector<ColorButton*>.