PDA

View Full Version : Design buttons with custom shapes



LuisLoez89
22nd April 2015, 13:24
Hello everyone!
I am trying to desing a sequence of custom buttons with arrow shape but I could not find the way. I need something like the buttons that you can see in the next picture in order to manage the workflow of my program and guide the user through it.
11119

Any help or suggestion is welcome.
Thanks for your help.

Santosh Reddy
22nd April 2015, 13:38
Do you want Buttons or Progress Indicators?

LuisLoez89
22nd April 2015, 13:45
Hello Santosh Reddy.
I want buttons. The main idea is that each button will launch a wizard dialog to perform each step. Then, when this step is finished the next button will be enabled. So the buttons should change its color and being enabled sequentially guiding the user throught the workflow.

Thanks

anda_skoa
22nd April 2015, 14:47
My approach would be to do this as a custom widget.
Either direct painting or with a graphicsview and arrow shaped items.

Cheers,
_

Santosh Reddy
22nd April 2015, 15:58
Here is one approach using QPushButton Button, see if it fits your need

11122




QWidget widget;

for(int i = 0; i < 4; i++)
{
QPushButton * button = new QPushButton(QString("Step %1").arg(i + 1), &widget);

if((i == 0) or (i == 2))
{
button->setEnabled(true);
}
else
{
button->setEnabled(false);
}

QPixmap pixmap;

if(i == 0)
{
pixmap = QPixmap("C:/Left.png");
}
else if(i == 3)
{
pixmap = QPixmap("C:/Right.png");
}
else
{
pixmap = QPixmap("C:/Mid.png");
}

button->setFixedSize(110,68);

button->setMask(pixmap.mask());

button->setGeometry((110 - 40) * i, 0, 110, 68);
}

widget.show();


Here are the mask files (some quick drawing using GIMP)

11123

11124

11125

LuisLoez89
22nd April 2015, 16:21
Thanks! It looks great but I am having a problem in the line "button->setMask(pixmap.mask());". It is the next error:

error: C2027: use of type 'QBitmap' undefined.

I don't know how to solve it.
Thanks for your help


SOLVED! I need to include QBitMap to use this method.
Thanks for your help!!

Santosh Reddy
22nd April 2015, 16:39
I used QPixmap not QBitmap.

Does the sample code work in your setup?

LuisLoez89
22nd April 2015, 17:36
Yes I am using QPixmap too but it seems that you need include QBitmap to use the .mask() method.

It is working fine! I need make some changes but your example was really usefull to understand the use of the masks.

Thanks