QT笔记
1.菜单栏上的弹出窗口
void MainWindow::on_new_action_triggered()
{
MyDialog myDialog;//MyDialog是一个ui
myDialog.setModal(true);
myDialog.exec();
/*******上面的写法弹出的窗口挡住后面的窗口***********/
/*******下面的写法弹出的窗口不挡住后面的窗口,并且可以弹出多个****/
// myDialog = new MyDialog(this);
// myDialog->show();
}
2.水平布局&垂直布局
QWidget *window = new QWidget;
window->setWindowTitle("Layout测试");
QPushButton *button1 = new QPushButton("one");
QPushButton *button2 = new QPushButton("two");
QPushButton *button3 = new QPushButton("three");
QHBoxLayout * hlayout = new QHBoxLayout;
hlayout->addWidget(button1);
hlayout->addWidget(button2);
hlayout->addWidget(button3);
window->setLayout(hlayout);
window->show();
QVBoxLayout * hlayout = new QVBoxLayout;//垂直布局
void Mainwindow::init(){
vBoxLayout = new QVBoxLayout(this);
topWidget = new QWidget;
topWidget->setStyleSheet("background:#FFCCCC");
topWidget->setMaximumHeight(50);
topWidget->setMinimumHeight(50);
vBoxLayout->addWidget(topWidget);
mainWidget = new QWidget;
mainWidget->setStyleSheet("background:#0099CC");
vBoxLayout->addWidget(mainWidget);
mainVBoxLayout = new QVBoxLayout(mainWidget);
//定义一个垂直布局,垂直布局放到mainWidget中
//MAX_X MAX_Y 都在.h中预定义
for(int i = 0 ; i < MAX_X ; i++){
mainHBoxLayout[i] = new QHBoxLayout();//新建一个水平布局
for(int j = 0 ; j < MAX_Y ; j++){
buttons[i][j] = new QPushButton;
buttons[i][j]->setStyleSheet("background:black");
buttons[i][j]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
//Expanding填充
mainHBoxLayout[i]->addWidget(buttons[i][j]);
//将每一行的button添加到水平布局
}
mainVBoxLayout->addLayout(mainHBoxLayout[i]);
//将水平布局添加到垂直布局中
}
}
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/2A/A1/wKioL1OEWjGB7FixAAG0BdoWs9U446.jpg" title="QQ截图20140527172030.png" alt="wKioL1OEWjGB7FixAAG0BdoWs9U446.jpg" />
3.小球碰撞边框反弹算法
void MainWindow::slotBallMove(){
//小球的坐标
int mx = ball.x() + ball.width() / 2;
int my = ball.y() + ball.height();
if(my >= bat.y()){
if(mx >= bat.x() && mx <= bat.x() + bat.width()){
dy = -1;
}
else{
timer.stop();
emit signalGameOver();
}
}
else if(x > this->width() - ball.width()){
dx = -1;
}
else if(y < 0){
dy = 1;
}
else if(x < 0){
dx = 1;
}
x += dx;
y += dy;
ball.move(x, y);
}
4.弹出的messageBox
QMessageBox::information(this, "提示", "*** Game Over ***", QMessageBox::Ok);
5.设置ico图标
myapp.rc//放在项目目录下
IDI_ICON1 ICON DISCARDABLE "appico.ico"
//然后在.pro文件中添加下面的语句
RC_FILE = myapp.rc
6.获取屏幕分辨率、计算机最佳显示位置,最小window大小
QDesktopWidget* desktopWidget = QApplication::desktop();
//获取可用桌面大小
QRect deskRect = desktopWidget->availableGeometry();
//获取设备屏幕大小
QRect screenRect = desktopWidget->screenGeometry();
int screenX = screenRect.width();
int screenY = screenRect.height();
int screenCount = desktopWidget->screenCount();//可用的显示器数
int appWidth = 1000;
int appHeight = 618;
int x_p = screenX/2 - appWidth/2;//计算出居中显示位置
int y_p = screenY/2 - appHeight/2;
this->setGeometry(x_p, y_p, appWidth, appHeight);
this->setMinimumHeight(appHeight);
this->setMinimumWidth(appWidth);
qDebug() << screenX << screenY << screenCount;
本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/1411247
QT笔记的更多相关文章
- QT笔记之解决QT5.2.0和VS2012中文乱码 以及在Qt Creator中文报错
转载:http://bbs.csdn.net/topics/390750169 VS2012 中文乱码 1.方法一: 包含头文件 #include <QTextCodec> ....... ...
- QT笔记之VS开发程序遇到的问题
转载:http://www.cnblogs.com/li-peng/p/3644812.html 转载:http://www.cnblogs.com/csuftzzk/p/VS_Qt_Experien ...
- QT笔记之不规则窗口的实现
QT实现的不规则窗口,是根据图片的形状显示 1.去标题栏 2.设置窗口背景为透明色 3.最后给窗口设置背景色 注:背景图为镂空的 格式为.png 图片资源下载:http://pan.baidu.com ...
- QT笔记之模态对话框及非模态对话框
模态对话框(Modal Dialog)与非模态对话框(Modeless Dialog)的概念不是Qt所独有的,在各种不同的平台下都存在.又有叫法是称为模式对话框,无模式对话框等.所谓模态对话框就是在其 ...
- QT笔记之QLineEdit自动补全以及控件提升
转载:http://www.cnblogs.com/csuftzzk/p/qss_lineedit_completer.html?utm_source=tuicool&utm_medium=r ...
- QT笔记之VS2010 Qt中导入qrc资源文件
转载1:http://qimo601.iteye.com/blog/1404693 转载2:http://blog.sina.com.cn/s/blog_92cde3060101lobm.html 转 ...
- QT笔记之实现阴影窗口
方法一: 代码实现 在窗口构造函数中加入:setAttribute(Qt::WA_TranslucentBackground),保证不被绘制上的部分透明 重写void paintEvent(QPain ...
- QT笔记之自定义窗口拖拽移动
1.QT自定义标题栏,拖拽标题栏移动窗口(只能拖拽标题,其他位置无法拖拽) 方法一: 转载:http://blog.sina.com.cn/s/blog_4ba5b45e0102e83h.html . ...
- 自学QT笔记
前言: Qt 是一个跨平台的 C++图形用户界面库,由挪威 TrollTech 公司于1995年底出品. Trolltech 公司在 1994 年成立,但是在 1992 年,成立 Trolltech ...
- QT笔记(1)--QT编程环境搭建
一.QT简介 Qt 是一个1991年由奇趣科技开发的跨平台C++图形用户界面应用程序开发框架.它既可以开发GUI程序,也可用于开发非GUI程序,比如控制台工具和服务器.Qt是面向对象的框架,使用特殊 ...
随机推荐
- 解决PHP生成UTF-8编码的CSV文件用Excel打开乱码的问题
在要输出的内容前先输出"\xEF\xBB\xBF", eg:要输出的内容保存在$content里$content = "\xEF\xBB\xBF".$conte ...
- 【转】解决eclipse无法设置NDK问题
参考:http://jingyan.baidu.com/album/4d58d5413000a09dd4e9c0fe.html?picindex=1 到android sdk官网下载r23版本的ad ...
- ffmpeg 转成MP3采样率8000
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- BP神经网络推导过程详解
BP算法是一种最有效的多层神经网络学习方法,其主要特点是信号前向传递,而误差后向传播,通过不断调节网络权重值,使得网络的最终输出与期望输出尽可能接近,以达到训练的目的. 一.多层神经网络结构及其描述 ...
- 【poj1160】 Post Office
http://poj.org/problem?id=1160 (题目链接) 题意 按照递增顺序给出一条直线上坐标互不相同的n个村庄,要求从中选择p个村庄建立邮局,每个村庄使用离它最近的那个邮局,使得所 ...
- C语言之socket获取网页源码
写爬虫也许你用的是python,类似urlopen(url).read()即可获得普通的网页的源码,或者用的java的网络库加上流操作,或者其他高级语言.但你有没有想过使用C语言来实现呢?我曾经以为用 ...
- Android成长日记-使用ViewFlipper实现屏幕切换动画效果
(一) ViewFlipper介绍 Android系统自带的一个多页面管理控件,它可以实现子界面的自动切换 (二) 为ViewFlipper加入View 1. 静态导入:在Layout布局文件中直接导 ...
- Tiny C Compiler(Tcc)
catalog . Tcc introduction . Tcc安装配置 . Tcc Programing 1. Tcc introduction TCC基本和GCC兼容 . 符合ANSI C(C8 ...
- 关于《加密与解密》的读后感----对dump脱壳的一点思考
偶然翻了一下手机日历,原来今天是夏至啊,时间过的真快.ISCC的比赛已经持续了2个多月了,我也跟着比赛的那些题目学了2个月.......虽然过程很辛苦,但感觉还是很幸运的,能在大三的时候遇到ISCC, ...
- Java 线程池的使用
转载原文链接: http://www.cnblogs.com/dolphin0520/p/3932921.html 在前面的文章中,我们使用线程的时候就去创建一个线程,这样实现起来非常简便,但是就会有 ...