Qt 4.6で簡単なゲームを作ろうとしています。アイデアは2つのウィジェットを持つことです.1つはメインウィンドウウィジェットで、スペースを表し、2つ目はスペース(親)内のスターシップウィジェットです。 簡素化されたコードは次のようになります別の1つのウィジェットを別のペイントにペイントする際の問題
私はコンパイル/*this is ship and child widget*/
class MyRect : public QWidget {
Q_OBJECT
public:
MyRect(QWidget* parent)
: QWidget(parent)
{
itsParent = parent;
itsx = 120;
itsy = 250;
itsw = 110;
itsh = 35;
body = new QRect(itsx, itsy, itsw, itsh);
}
~MyRect() {}
protected:
void paintEvent(QPaintEvent *event);
private:
int itsx;
int itsy;
int itsw;
int itsh;
QRect* body;
QWidget* itsParent;
};
void MyRect::paintEvent(QPaintEvent *event)
{
QPen pen(Qt::black, 2, Qt::SolidLine);
QColor hourColor(0, 255, 0);
QPainter painter(itsParent);
painter.setBrush(hourColor);
painter.setPen(pen);
painter.drawRect(*body);
}
/*this is space and main window widget*/
class space : public QMainWindow
{
Q_OBJECT
public:
space(QWidget *parent = 0);
~space();
protected:
private:
MyRect* ship;
};
space::space(QWidget *parent)
: QMainWindow(parent)
{
ship = new MyRect(this);
}
、画面が空白で、長方形MyRect::body
が描かれていません。 私はQtのオンラインドキュメントをチェックし、運がないGoogleの調査をしました。 これについての説明は大歓迎です。私は別の(親)に1つのウィジェットを描きたい。
QGraphicsViewもご覧ください。 –