当前位置: 首页>>代码示例>>C++>>正文


C++ QCheckBox::setParent方法代码示例

本文整理汇总了C++中QCheckBox::setParent方法的典型用法代码示例。如果您正苦于以下问题:C++ QCheckBox::setParent方法的具体用法?C++ QCheckBox::setParent怎么用?C++ QCheckBox::setParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QCheckBox的用法示例。


在下文中一共展示了QCheckBox::setParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[]) {
	QApplication app(argc, argv);

	/* 常數們 */
	int boardSize = BOARD_SIZE;
	int stoneSize = STONE_SIZE;
	int boardWidth = stoneSize*boardSize;

	/* 新視窗 */
	QWidget *window = new QMouseEventWindow;
	window->setWindowTitle("ReversiGrid");
	window->setFixedSize(boardWidth+200, boardWidth);
	QWidget *board = new QWidget(window);
	board->setFixedSize(boardWidth, boardWidth);

	/* 載入棋子圖片 */
	QPixmap *stoneWPix = new QPixmap(":/img/stoneW.png");
	QPixmap *stoneWPixS = new QPixmap;
	*stoneWPixS = stoneWPix->scaled(stoneSize, stoneSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	QPixmap *stoneBPix = new QPixmap(":/img/stoneB.png");
	QPixmap *stoneBPixS = new QPixmap;
	*stoneBPixS = stoneBPix->scaled(stoneSize, stoneSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	QPixmap *stoneWaPix = new QPixmap(":/img/stoneWa.png");
	QPixmap *stoneWaPixS = new QPixmap;
	*stoneWaPixS = stoneWaPix->scaled(stoneSize, stoneSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	QPixmap *stoneBaPix = new QPixmap(":/img/stoneBa.png");
	QPixmap *stoneBaPixS = new QPixmap;
	*stoneBaPixS = stoneBaPix->scaled(stoneSize, stoneSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	QPixmap *stoneWsPix = new QPixmap(":/img/stoneWs.png");
	QPixmap *stoneWsPixS = new QPixmap;
	*stoneWsPixS = stoneWsPix->scaled(stoneSize, stoneSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	QPixmap *stoneBsPix = new QPixmap(":/img/stoneBs.png");
	QPixmap *stoneBsPixS = new QPixmap;
	*stoneBsPixS = stoneBsPix->scaled(stoneSize, stoneSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
	QPixmap *nullPix = new QPixmap(":/img/null.png");


	/* 棋盤網格排版 */
	QGridLayout *grid = new QGridLayout;
	grid->setSpacing(0);
	grid->setMargin(0);
	grid->setGeometry(QRect(0, 0, 10, 100));

	/* 構建棋盤 */
	QLabel *square[BOARD_SIZE*BOARD_SIZE];
	for (int i=0; i<boardSize; i++) {
		for (int j=0; j<boardSize; j++) {
			square[i*BOARD_SIZE+j] = new QLabel;
			square[i*BOARD_SIZE+j]->setFrameStyle(QFrame::Panel + QFrame::Sunken);
			square[i*BOARD_SIZE+j]->setAlignment(Qt::AlignCenter);
			square[i*BOARD_SIZE+j]->setAttribute(Qt::WA_TranslucentBackground);
			// square[i*BOARD_SIZE+j]->setPixmap();
			square[i*BOARD_SIZE+j]->setAttribute(Qt::WA_TransparentForMouseEvents, true);
			grid->addWidget(square[i*BOARD_SIZE+j], i, j);
		}
	}
	QLabel *turnT = new QLabel(window);
	turnT->setGeometry(boardWidth, 20, 200, 14);
	turnT->setText("<center>Next move:</center>");
	QLabel *turn = new QLabel(window);
	turn->setGeometry(boardWidth+100-(STONE_SIZE/2), 45, STONE_SIZE, STONE_SIZE);
	turn->setFrameStyle(QFrame::Sunken);

	/* 遊戲物件 */
	game = new Game(square, turn,
		stoneWPixS, stoneBPixS,
		stoneWaPixS, stoneBaPixS,
		stoneWsPixS, stoneBsPixS,
		nullPix);

	/* UI */
	QCheckBox *hintCheckBox = new QCheckBox("Show hints");
	hintCheckBox->setParent(window);
	hintCheckBox->setGeometry(boardWidth+50, 210, 100, 20);
	QObject::connect(hintCheckBox, SIGNAL(stateChanged(int)), game, SLOT(hintSwitch(int)));

	QLabel *bScore = new QLabel(window);
	bScore->setGeometry(boardWidth, 100, 200, 14);
	bScore->setText("<center>Black</center>");
	QLabel *wScore = new QLabel(window);
	wScore->setGeometry(boardWidth, 150, 200, 14);
	wScore->setText("<center>White</center>");
	QLCDNumber *lcdB = new QLCDNumber(window);
	QLCDNumber *lcdW = new QLCDNumber(window);
	lcdB->setGeometry(boardWidth+50, 120, 100, 24);
	lcdW->setGeometry(boardWidth+50, 170, 100, 24);
	QObject::connect(game, SIGNAL(updateBScore(int)), lcdB, SLOT(display(int)));
	QObject::connect(game, SIGNAL(updateWScore(int)), lcdW, SLOT(display(int)));

	QCheckBox *aiBCheckBox = new QCheckBox("AI");
	aiBCheckBox->setParent(window);
	aiBCheckBox->setGeometry(boardWidth+140, 100, 50, 14);
	QObject::connect(aiBCheckBox, SIGNAL(stateChanged(int)), game, SLOT(aiBSwitch(int)));

	QCheckBox *aiWCheckBox = new QCheckBox("AI");
	aiWCheckBox->setParent(window);
	aiWCheckBox->setGeometry(boardWidth+140, 150, 50, 14);
	QObject::connect(aiWCheckBox, SIGNAL(stateChanged(int)), game, SLOT(aiWSwitch(int)));

	/* 按鍵 */
//.........这里部分代码省略.........
开发者ID:Neson,项目名称:QtReversi,代码行数:101,代码来源:main.cpp


注:本文中的QCheckBox::setParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。