You have to create the labels in main.cpp:
topLayout->addWidget(shoot);
topLayout->addStretch(1);
topLayout->addWidget( xLabel );
topLayout->addWidget( yLabel );
connect( cannonField, SIGNAL( updateBulletPosition(int,int) ), this, SLOT( setBulletPosition(int, int ) ) );
leftLayout->addWidget(angle);
leftLayout->addWidget(force);
gridLayout->addWidget(quit, 0, 0);
gridLayout->addLayout(topLayout, 0, 1);
gridLayout->addLayout(leftLayout, 1, 0);
gridLayout->addWidget(cannonField, 1, 1, 2, 1);
gridLayout->setColumnStretch(1, 10);
setLayout(gridLayout);
angle->setValue(60);
force->setValue(25);
angle->setFocus();
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(shoot);
topLayout->addStretch(1);
QLabel* mxLabel = new QLabel( this );
QLabel* myLabel = new QLabel( this );
topLayout->addWidget( xLabel );
topLayout->addWidget( yLabel );
connect( cannonField, SIGNAL( updateBulletPosition(int,int) ), this, SLOT( setBulletPosition(int, int ) ) );
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addWidget(angle);
leftLayout->addWidget(force);
QGridLayout *gridLayout = new QGridLayout;
gridLayout->addWidget(quit, 0, 0);
gridLayout->addLayout(topLayout, 0, 1);
gridLayout->addLayout(leftLayout, 1, 0);
gridLayout->addWidget(cannonField, 1, 1, 2, 1);
gridLayout->setColumnStretch(1, 10);
setLayout(gridLayout);
angle->setValue(60);
force->setValue(25);
angle->setFocus();
To copy to clipboard, switch view to plain text mode
In the MyWidget class declaration:
{
public:
public slots:
void setBulletPosition( int x, int y );
private:
};
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
public slots:
void setBulletPosition( int x, int y );
private:
QLabel* mxLabel;
QLabel* myLabel;
};
To copy to clipboard, switch view to plain text mode
the slot:
void MyWidget::setBulletPostion( int x, int y )
{
mxLabel
->setText
( QVariant(x
).
toString() );
myLabel
->setText
( QVariant(y
).
toString() );
}
void MyWidget::setBulletPostion( int x, int y )
{
mxLabel->setText( QVariant(x).toString() );
myLabel->setText( QVariant(y).toString() );
}
To copy to clipboard, switch view to plain text mode
This is it, pretty much. I'm not sure if the labels will appear correctly ( int the top-right corner ), but that can be fixed easily.
Bookmarks