1

私が知っていることはすべて試しましたが、この問題は私の頭の中にあるという結論に達しました。repaint()、update()、および this->update(); を実行してみました。そして私が考えることができる他のすべて。Pixmap は関数の外側 (コンストラクター内) で機能しますが、関数内では機能しません。コードは次のとおりです(関連するもののみを貼り付けます。さらに必要な場合は指定してください):

myWidget.h

#define NUM_POINTERS 10


QLabel* pointerArray[NUM_POINTERS];
QPixmap circle;
QPixmap* triangle;
QPixmap* whitex;
int activePointer;

myWidget.cpp

activePointer = 0;

QPixmap circle (":/Resources/greencircle.png");
this->whitex = new QPixmap(":/Resources/white_x.png");
this->triangle = new QPixmap(":/Resources/redtriangle.png");

//create an array of pointers to the label1-10 objects
pointerArray[0] = ui->label1;
pointerArray[1] = ui->label2;
pointerArray[2] = ui->label3;
...
pointerArray[9] = ui->label10;

for (int i = 0;i < 10; i++)
{
    pointerArray[i]->setPixmap(circle);
}

void myWidget::changeImage()
{
  updatesEnabled();
  if (activePointer < 10){
      pointerArray[activePointer]->setPixmap(*this->whitex);
      activePointer++;
      update();
}
  else{
      printf("end of array\n");
      fflush(stdout);
  }

}

必要な場所に円の列が印刷されますが、白い X は表示されません。ピックスマップは whitex に変更されますが、更新されません。クラッシュすることはなく、配列の最後まで activePointer に追加し続けます。

前もって感謝します。

クイック編集: pointerArray[activePointer]->update(); を試しました。運がない。

4

0 に答える 0