A
A
Alexander Sharomet2014-11-20 10:38:50
Programming
Alexander Sharomet, 2014-11-20 10:38:50

How to add many pictures in a loop in Qt Creator?

Hello! I say right away that I am not a very good programmer, or rather a programmer in a completely different field.
I'm making a minesweeper game in qt crearoe (qt widgets) (this is required for my coursework).
And I don’t know how to add pictures to the scene in the cycle. I add pictures to the label, but it turns out that if I need to add 10 pictures, then I need to add 10 label components?
How can this be implemented? maybe there are better ways? Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
TriKrista, 2014-11-20
@sharomet

Yes, you will have to add the required number of QLabels and group them in the layout.
QLabel, it is desirable to add to a double array or container, for the convenience of their further use.
Here is a small example:

QVector<QVector<QLabel *> > array;
QGridLayout *layout;
...
for (int i = 0; i < 10; i++) {
    QVector<QLabel *> list;
    for (int j = 0; j < 10; j++) {
         list << new QLabel(); // или ваш вариант label
         layout->addWidget(list[j], i, j);
    }
    array << list;
}
...

A
Alexey, 2014-11-20
@MAKAPOH

Look at the Graphics View Framework , in my opinion it is more convenient to make a minesweeper game on it.

D
DancingOnWater, 2014-11-20
@DancingOnWater

Look at the Graphics View Framework, as already suggested, or at QtQuick.
If you desperately need it on widgets, then inherit from Qwidget and draw pictures for yourself in paintEvent

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question