14 int main(
int argc,
char** argv)
16 QApplication app(argc, argv);
18 wgt.setFixedSize(300, 50);
21 QLabel* plblOff =
new QLabel(
"Off");
22 QLabel* plblOn =
new QLabel(
"On");
24 QHBoxLayout* phbx =
new QHBoxLayout;
25 phbx->addWidget(plblOn);
27 phbx->addWidget(plblOff);
30 QPushButton* pcmd =
new QPushButton(
"Push", &wgt);
31 pcmd->setAutoFillBackground(
true);
34 int nButtonWidth = wgt.width() / 2;
36 QStateMachine* psm =
new QStateMachine;
38 QState* pStateOff =
new QState(psm);
39 QRect rect1(0, 0, nButtonWidth, wgt.height());
40 pStateOff->assignProperty(pcmd,
"geometry", rect1);
41 pStateOff->assignProperty(plblOff,
"visible",
true);
42 pStateOff->assignProperty(plblOn,
"visible",
false);
43 psm->setInitialState(pStateOff);
45 QState* pStateOn =
new QState(psm);
46 QRect rect2(nButtonWidth, 0, nButtonWidth, wgt.height());
47 pStateOn->assignProperty(pcmd,
"geometry", rect2);
48 pStateOn->assignProperty(plblOff,
"visible",
false);
49 pStateOn->assignProperty(plblOn,
"visible",
true);
51 QSignalTransition* ptrans1 =
52 pStateOff->addTransition(pcmd, SIGNAL(clicked()), pStateOn);
54 QSignalTransition* ptrans2 =
55 pStateOn->addTransition(pcmd, SIGNAL(clicked()), pStateOff);
57 QPropertyAnimation* panim1 =
58 new QPropertyAnimation(pcmd,
"geometry");
59 ptrans1->addAnimation(panim1);
61 QPropertyAnimation* panim2 =
62 new QPropertyAnimation(pcmd,
"geometry");
63 ptrans2->addAnimation(panim2);
int main(int argc, char **argv)