How to Show a 2D QLabel?



  • Hi, I have this code for a Maze, but don't know how to show it to the widow, I know that I have to add it to a Widget, but don't know WHERE and HOW to place it.

    My Actual Code Here
    @
    QPixmap test("Image_PATH_Here");
    QWidget mainWidget = new QWidget;
    QLabel maze;
    maze= new QLabel
    [x];
    for (int i = 0; i < x; i++) {
    maze[i]= new QLabel[y];
    }
    for(int i=0;i<x;i++){
    for(int j=0;j<y;j++){
    maze[i][j].setPixmap(test);
    maze[i][j].move(i
    60,j
    60);
    }
    }
    mainWidget->show();
    setCentralWidget(mainWidget);
    @

    Thanks for your time. I'm new on this, sorry for this simple question guys.



  • You can do it with layouts - add this lines:
    @
    QHBoxLayout tlay;
    for(int i=0;i<x;i++){
    for(int j=0;j<y;j++){
    tlay.addWidget(&maze[i][j]);
    }
    }
    mainWidget->setLayout(&tlay);
    @

    and don't forget to include
    @
    #include <QHBoxLayout>
    @



  • [quote author="MrMNight" date="1394528192"]You can do....
    @[/quote]

    Hey thanks for your answer, but they just show the images in a row, I already tried to use QGridLayout too, but there's an issue with the space between each image every time I tried to set a default position. But thanks anyway :)
    Now, I'm gonna try using the Libraries for Games in QT.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.