How to change the background color of the already existing QGraphicsProxyWidget?

123 views Asked by At

I have formed a grid layout with QGraphicsProxyWidgets which are Qlabel widgets added to a scene. I want to update the background color of the widgets with a button click.

How can I access the QLabel so I can change the background color? I tried using a palette, but it caused the program to crash.

void MainWindow::changeBackgroundOfButtons()
{

int itemCount = layout->count();

int numCols = 4;
int row = 0, col = 0;
for (int i = 0; i < itemCount; ++i)
{
    QGraphicsProxyWidget *currentWidget = dynamic_cast<QGraphicsProxyWidget*>(layout->itemAt(row, col));

    QPalette p(palette());
    p.setColor(QPalette::Base, Qt::lightGray);
    currentWidget->setPalette(p);

    col++;
    if (col == numCols) row++;
    col = col % numCols;
}

}
0

There are 0 answers