PDA

View Full Version : Button Function



Kuushie118
24th January 2019, 21:35
Is there a way to pop out multiple images after pressing a button? and you can set the coordinate of the images to the location where you want each images to be?
I'm planning to make like a card animation where if the user were to press the play button, the cards from the draw pile will give random 5 cards to the players side. For now, I'm planning to only have two players as a test. So 5 cards will be randomly place to player 1 side and the player 2 side to play.
If possible, I don't want to use any qml images or any .ui for this program.

I hope I'm making sense here. Thanks.

d_stranz
25th January 2019, 16:09
Your program can do anything you code it to do if you connect a slot to the button's clicked() signal. And using a button click to start a simulated deal of hands of cards is only one way you might do it. The two are related only if you chose to use a button for that purpose. Don't get locked into confusing how you accomplish a goal with the goal itself.

As for displaying the game cards, the Qt Graphics / View framework is one way to do that. You can use QGraphicsPixmapItem instances with JPG or other images to represent the cards. To simulate dealing, you can animate the position of the cards using the Qt Animation framework.

I would suggest that you start simple. Instead of jumping into the deep end, develop a simulation that uses simple rectangles instead of card images. Learn how to use the Graphics / View architecture to create a QGraphicsScene containing the rectangles and to place the rectangles where you want them in the scene (and scaled to fit on the QGraphicsView). When you get that working, add code to move the rectangles around using a controlled animation. When that is working, find playing card images and replace the rectangles with pixmap items and those images. When that is working, add the code that implements the rules of your card game and the user interface elements your users will need to control the game and display the scores, etc.

anda_skoa
26th January 2019, 08:44
If possible, I don't want to use any qml images or any .ui for this program.


These seem like rather arbitrary restrictions.

If you are using QML/QtQuick, why not use its image type?
If you are using QtWidgets, why manually code all UI?

Cheers,
_

d_stranz
26th January 2019, 17:15
These seem like rather arbitrary restrictions.

Sometimes all the technology available in Qt can be overwhelming.