I am trying to make a chess game. So I am placing the board,coins 开发者_运维知识库as labels in a widget. Now I want to make the chess board as a non-movable label. Because if I clicks and moves the board, it's moving. How to constraint it.
You might want to look into the Qt Graphics View Framework. A QGraphicsScene would be more appropriate for what you are trying to do.
Quote from the documentation:
The
QGraphicsScene
class provides a surface for managing a large number of 2D graphical items.The class serves as a container for QGraphicsItems. It is used together with QGraphicsView for visualizing graphical items, such as lines, rectangles, text, or even custom items, on a 2D surface. QGraphicsScene is part of The Graphics View Framework.
I think you are using the wrong tool.
IMHO: You have to paint the board manually,or use graphics scene for this.
I also agree you should be using graphicsview or something else but to answer your question you could to this
label->setFixedSize(/*a qsize or to ints are passed see http://doc.qt.nokia.com/4.6/qwidget.html#setFixedSize*/);
I would do
label->setFixedSize (label->sizeHint()) this will make sure the size is fixed but it is the labels optimum size (all content is visible)
精彩评论