Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to Show a 2D QLabel?
Forum Updated to NodeBB v4.3 + New Features

How to Show a 2D QLabel?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 936 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vitaR
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MrMNight
      wrote on last edited by
      #2

      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>
      @

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vitaR
        wrote on last edited by
        #3

        [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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved