PDA

View Full Version : QPushButton function



maider
22nd October 2009, 10:07
Hey!

I'm trying to insert a load of qpushbuttons with their own two images on the grounds that they are checkeable buttons but with a function. I want to do like this to simplify the code.

My question is: How can I crontol where i put the buttons if i don't use a combox?
I don't want to use combox because of the fact that i want to have the button and the images with the measure that i need.

thanks!

caduel
22nd October 2009, 10:15
sorry, I don't understand the questio. can you rephrase it, please?

(What has all this to do with a combobox?)

maider
22nd October 2009, 10:41
Sorry, I was wrong!

I didn't want to say combox. I don't want to do with a QGridLayout, because I need to insert a load of checkeable buttons ,that are going to chance the imange if they are clicked or not, with the measure that i want.
The image is going to have the measure of the button to simulate as if they were checkeable images.

caduel
22nd October 2009, 10:58
why is this a reason not to use a QGridLayout?

you can also
* subclass QWidget, put your button and a QLabel with the second image in it
* subclass QPushButton and draw a second image on it

Maybe draw a picture that shows what you want to achieve?

maider
22nd October 2009, 11:17
ok this is a graphic example.

I

caduel
22nd October 2009, 11:29
i would probably do something like


class ButtonWithIcon : public QWidget
{
QAbstractButton *button_;
QLabel *state_;

public:
ButtonWithIcon(QWidget *parent=0) : QWidget(parent)
{
QHBoxLayout *l=new QHBoxLayout;
button_ = new QToolButton(...);
l->addWidget(button_);
state_ = new QLabel(...);
l->addWidget(state_);
setLayout(l);

button_->setCheckable(true);
connect(button_, SIGNAL(toggled(bool)), SLOT(onToggle(bool)));
}

private Q_SLOTS:
void onToggle(bool on)
{
state_->setPixmap(... depending on on ...);
}

};

A drawback is that the class itself is not a subclass of QAbstractButton.

HTH

maider
22nd October 2009, 11:41
ok! i will try it!
i will comment later.
thanks!

Junior
22nd October 2009, 15:01
Here is an example using properties and checking the state as well.

Junior