用于 Qt 按钮集合的数据类型
我是 Qt 的新手,需要开发 Mancala 游戏。由于我对 Qt 环境是全新的,因此我计划让事情变得非常简单。我将使用“Push Button”小部件作为游戏的一部分。由于两个玩家玩这个游戏,我的想法是要有一系列按钮。一个数组用于玩家 1,另一个数组用于玩家 2。我的问题是,由于我使用的是“按钮”小部件,如何将它们分组以进行迭代?我注意到 Qt 同时具有数组和矢量数据类型,但我对如何使用这些数据类型对按钮进行“分组”感到困惑。有谁知道有任何示例代码或教程可以查看以了解更多信息吗?
感谢您抽出时间并提供任何意见。
I am brand new to Qt and need to develop the Mancala game. Since I'm brand new to the Qt environment, my plan it to keep things very simple. I will be using the "Push Button" widget as pieces on the game. Since two players play this game, my idea is to have to arrays of buttons. One array for player 1 and the other for player 2. My question is since I am using "Push Button" widgets, how can I group them to iterate through? I notice that Qt has both the array and vector data types but I'm confused on how these data types can be used to "group" the buttons. Does anyone know of any sample code or tutorials to look at to learn more?
Thanks for your time and any input provided.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑专门针对一组按钮使用 QButtonGroup 类。
一般来说,在 Qt 中,拥有动态数组的公认方法是使用 QVector 类。它是一个高级类,有点类似于 STL 的
vector
。Consider using the QButtonGroup class specifically for a group of buttons.
Generally in Qt the accepted way to have a dynamic array of things is to use the QVector class. It's a high-level class somewhat similar to STL's
vector
.不知道曼卡拉,但如果它是固定大小的板,您最好将其作为网格并让网格单元响应按钮按下吗?
然后一切都由tablewidget处理
Don't know mancala but if it is a fixed size board are you better doing this as a grid and having the grid cells respond to a button push?
Then it's all handled by the tablewidget