Best way to show a maze? Best way to implement it?
-
Hi, I'm new using QT, so I have to make a simple Graphic Interface, in this App I have to show a Maze.
I have the whole logic of the code in c++ language. In this maze there are two characters, a cat and a mouse, they go throw the maze trying to find a path to the exit, so I have to use a Timer each second they made a move and then I have to Repaint The frame (Sorry, I know that in Java is called Frame, don't know if in QT is Window or Frame too).I have some single and simple questions.
- In java you could set NULL to a layout, and then you can set specific bounds and position to your component and add it to your Frame. In QT I always have to set a default layout? Yesterday I was searching about how to make a Bi-Dimensional of QLabel and show it in the frame (The Main Maze I'm gonna use), but the only way I could find to deploy to the window was using a QGridLayout, maybe there's more options, but that's the only I could found. The problem is when I run the project, there's a space between each label. "Image Here":http://imgur.com/HwACxCT And I don't want any space between them.
I want to have the control of each Label without using QGridLyout, cause I have to change the position of each character every second, so I have to reload the Bi-Dimensional Array.
2)How I make a Bi-Dimensional array of QLabel and add it to the window? This question have a connection with the first question actually, I tried to do this before doing the QGridLayout thing, but I just got some errors, and search throw forums without any solutions.
The Code I'm using to make this:
@
QWidget *mainWidget = new QWidget;
QGridLayout *layout = new QGridLayout;
for (int r = 0; r < 15; r++) {
for (int c = 0; c < 15; c++) {
QLabel *label = new QLabel("1", mainWidget);
label->setPixmap(test);
layout->addWidget(label, r, c);
}
}
mainWidget->setLayout(layout);
mainWidget->show();
setCentralWidget(mainWidget);
@Sorry if my questions are simple, I'm still learning how this works.
Thank you for your time. -
Only some small remarks, since I am trying to solve my own problems currently:
-
You do not need a layout. Just create a widget with a parent, then use its move()- and show()-methods to position and show them.
In the context of this the setContentsMargins() functions of widgets (and layouts) may be useful, too. -
Layouts have a method "setSpacing" (name may be slightly off, just using my memory here). If you set it to 0, there should be no visible borders.
-
If you want a pretty solution, think about reimplementing the "paintEvent()":http://qt-project.org/doc/qt-5/qwidget.html#paintEvent of your widget. In there you can simply draw (using QPainter directly on the widget) whatever you want to display.
This approach would give you full control, and it would still be pretty easy to implement. But usually you have to take care that your paintEvent() doesn't eat too much processing power. "With great power...." - you probably know that one. ;)
-
-
Hi,
Not a direct answer to your question, but to me it seems that the QGraphicsView/Scene classes and friends would be more suited for your needs
-
[quote author="thEClaw" date="1394396111"]Only some small rem....[/quote]
Thank you for answering, with your answer and with a tutorial about widgets, I understand better what I have to do :)[quote author="SGaist" date="1394397038"]Hi, Not a direct answ...[/quote]
Thanks, maybe I'll try later, but not now cause, I'm very new on this and I just wanna end my project, once I do this, I can try new things, thanks for your reply :)