Qt 一些技巧积累
2013-07-17 11:14
316 查看
和查找的资料不同之处 在副窗口中添加子按钮 代码如下:
//在父窗口中添加子按钮
QWidget *window =new QWidget;
QPushButton *button1 = new QPushButton("one");
QPushButton *button2 = new QPushButton("two");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
window->setLayout(layout);
window->show();
//额外添加的一个按钮
QPushButton *button3 = new QPushButton ("Hello World",0);
头文件是#include <QVBoxLayout>
例子:
//额外添加的一个按钮
QPushButton *button3 = new QPushButton ("Hello World",0);
//在父窗口中添加子按钮
QWidget *window =new QWidget;
QPushButton *button1 = new QPushButton("one");
QPushButton *button2 = new QPushButton("two");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
window->setLayout(layout);
window->show();
创建一个单独的按钮代码如下:
//单独的一个按钮
QPushButton hello("Hello World",0);
hello.resize(200,100);
hello.setFont(QFont("Times",18,QFont::Bold));
hello.show();
头文件是:
#include <qapplication.h>
#include <qpushbutton.h>
创建listview
1。 /* QStandardItemModel *model = new QStandardItemModel;
model->setItem(0, 0, new QStandardItem("January"));
model->setItem(1, 0, new QStandardItem("February"));
model->setItem(0, 1, new QStandardItem("10,000"));
model->setItem(1, 1, new QStandardItem("20,000"));
QTableView *view1 = new QTableView;
view1->setModel(model);
// QTableView *view2 = new QTableView;
//view2->setModel(model);
view1->show();
//view2->show();*/
2.
/* QStandardItemModel *model = new QStandardItemModel();
for (int i = 0; i < 5; i++)
{
QStandardItem *item = new QStandardItem();
item->setText("item");
model->appendRow(item);
}
ui->listView->setModel(model);
ui->listView->show();
ui->listView->update();*/
/* QFrame *frame = new QFrame;
frame->setObjectName("myframe");
frame->resize(400,700);
frame->setStyleSheet("QFrame#myframe{border-image:url(images/frame.jpg)}");
frame->show();*/
/* Client *form = new Client;
form->setObjectName("myframe");
form->resize(320,480);
form->setStyleSheet("QFrame#myframe{border-image:url(images/cow.png)}");
form->show();*/
treeWidget添加小图标
imageItem1->setIcon(0,QIcon("images/1.png"));图片要是PNG格式不然现实不出来
QT tableView实现双击获取选中行的值
(2013-04-10 21:41:23)
标签:
linuxqt编程
分类: 学习笔记
在tableView控件上右键go to slot 选择doubleClicked进入函数。
void MainDialog::on_tableView_doubleClicked(const QModelIndex &index)
{
QAbstractItemModel *Imodel=ui->tableView->model();
QModelIndex Iindex = Imodel->index(index.row(),1);//index.row()为算选择的行号。1为所选中行的第一列。。
QVariant datatemp=Imodel->data(Iindex);
QString name=datatemp.toString();//name即为所选择行的第一列的值。。。
}
网址:http://blog.sina.com.cn/s/blog_832c702d01017sfk.html
tableview内容居中
网址:http://www.qtbcw.com/thread-9-1-1.html
多窗口切换
网址:http://blog.163.com/wei_j_b/blog/static/18354130820113111145557/
http://blog.163.com/wei_j_b/blog/static/18354130820113111145557/
QComboBox:
获取QComboBox当前选择的内容:
QString QComboBox::currentText () const
QString strcom1 = ui->comboBox->currentText();
打开字窗口隐藏父窗口的函数是
this->hide();//隐藏父窗口
要打开的子窗口的指针->show();
网址:http://www.bcwhy.com/thread-17852-1-1.html
最近公司在做一个项目,功能做的差不多了,现在是界面方面修改,要想做出好看的界面,标题栏是个问题,所以我选择把标题栏去掉,去掉标题栏方法比较简单,就一行代码
this->setWindowFlags(Qt::FramelessWindowHint);
去掉以后又发现一个问题,就是不能移动窗口了,于是我就重写了三个鼠标事件,大致代码如下
.h文件的代码:
#include <QMouseEvent>
protected:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
private:
QPoint last;
.cpp文件的代码
//可以在构造函数中初始一下last变量用其成员函数setX,setY就是了
//接下来就是对三个鼠标事件的重写
void MainWindow::mousePressEvent(QMouseEvent *e)
{
last = e->globalPos();
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
int dx = e->globalX() - last.x();
int dy = e->globalY() - last.y();
last = e->globalPos();
move(x()+dx, y()+dy);
}
void MainWindow::mouseReleaseEvent(QMouseEvent *e)
{
int dx = e->globalX() - last.x();
int dy = e->globalY() - last.y();
move(x()+dx, y()+dy);
}
复制过去用的时候记得把类名改掉哦~
这样就OK了,去掉窗口标题栏后还能拖动窗体
//在父窗口中添加子按钮
QWidget *window =new QWidget;
QPushButton *button1 = new QPushButton("one");
QPushButton *button2 = new QPushButton("two");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
window->setLayout(layout);
window->show();
//额外添加的一个按钮
QPushButton *button3 = new QPushButton ("Hello World",0);
头文件是#include <QVBoxLayout>
例子:
//额外添加的一个按钮
QPushButton *button3 = new QPushButton ("Hello World",0);
//在父窗口中添加子按钮
QWidget *window =new QWidget;
QPushButton *button1 = new QPushButton("one");
QPushButton *button2 = new QPushButton("two");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
window->setLayout(layout);
window->show();
创建一个单独的按钮代码如下:
//单独的一个按钮
QPushButton hello("Hello World",0);
hello.resize(200,100);
hello.setFont(QFont("Times",18,QFont::Bold));
hello.show();
头文件是:
#include <qapplication.h>
#include <qpushbutton.h>
创建listview
1。 /* QStandardItemModel *model = new QStandardItemModel;
model->setItem(0, 0, new QStandardItem("January"));
model->setItem(1, 0, new QStandardItem("February"));
model->setItem(0, 1, new QStandardItem("10,000"));
model->setItem(1, 1, new QStandardItem("20,000"));
QTableView *view1 = new QTableView;
view1->setModel(model);
// QTableView *view2 = new QTableView;
//view2->setModel(model);
view1->show();
//view2->show();*/
2.
/* QStandardItemModel *model = new QStandardItemModel();
for (int i = 0; i < 5; i++)
{
QStandardItem *item = new QStandardItem();
item->setText("item");
model->appendRow(item);
}
ui->listView->setModel(model);
ui->listView->show();
ui->listView->update();*/
/* QFrame *frame = new QFrame;
frame->setObjectName("myframe");
frame->resize(400,700);
frame->setStyleSheet("QFrame#myframe{border-image:url(images/frame.jpg)}");
frame->show();*/
/* Client *form = new Client;
form->setObjectName("myframe");
form->resize(320,480);
form->setStyleSheet("QFrame#myframe{border-image:url(images/cow.png)}");
form->show();*/
treeWidget添加小图标
imageItem1->setIcon(0,QIcon("images/1.png"));图片要是PNG格式不然现实不出来
QT tableView实现双击获取选中行的值
(2013-04-10 21:41:23)
标签:
linuxqt编程
分类: 学习笔记
在tableView控件上右键go to slot 选择doubleClicked进入函数。
void MainDialog::on_tableView_doubleClicked(const QModelIndex &index)
{
QAbstractItemModel *Imodel=ui->tableView->model();
QModelIndex Iindex = Imodel->index(index.row(),1);//index.row()为算选择的行号。1为所选中行的第一列。。
QVariant datatemp=Imodel->data(Iindex);
QString name=datatemp.toString();//name即为所选择行的第一列的值。。。
}
网址:http://blog.sina.com.cn/s/blog_832c702d01017sfk.html
tableview内容居中
网址:http://www.qtbcw.com/thread-9-1-1.html
多窗口切换
网址:http://blog.163.com/wei_j_b/blog/static/18354130820113111145557/
http://blog.163.com/wei_j_b/blog/static/18354130820113111145557/
QComboBox:
获取QComboBox当前选择的内容:
QString QComboBox::currentText () const
QString strcom1 = ui->comboBox->currentText();
打开字窗口隐藏父窗口的函数是
this->hide();//隐藏父窗口
要打开的子窗口的指针->show();
网址:http://www.bcwhy.com/thread-17852-1-1.html
最近公司在做一个项目,功能做的差不多了,现在是界面方面修改,要想做出好看的界面,标题栏是个问题,所以我选择把标题栏去掉,去掉标题栏方法比较简单,就一行代码
this->setWindowFlags(Qt::FramelessWindowHint);
去掉以后又发现一个问题,就是不能移动窗口了,于是我就重写了三个鼠标事件,大致代码如下
.h文件的代码:
#include <QMouseEvent>
protected:
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
private:
QPoint last;
.cpp文件的代码
//可以在构造函数中初始一下last变量用其成员函数setX,setY就是了
//接下来就是对三个鼠标事件的重写
void MainWindow::mousePressEvent(QMouseEvent *e)
{
last = e->globalPos();
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
int dx = e->globalX() - last.x();
int dy = e->globalY() - last.y();
last = e->globalPos();
move(x()+dx, y()+dy);
}
void MainWindow::mouseReleaseEvent(QMouseEvent *e)
{
int dx = e->globalX() - last.x();
int dy = e->globalY() - last.y();
move(x()+dx, y()+dy);
}
复制过去用的时候记得把类名改掉哦~
这样就OK了,去掉窗口标题栏后还能拖动窗体
相关文章推荐
- Qt界面的一些技巧和实现笔记
- Qt设计时的一些技巧 (转)
- 最近使用QT开发的一些心得,技巧
- php积累的一些技巧
- 使用Linux五年积累的一些经验技巧
- QT界面(控件)相关设计的一些技巧总结
- Qt和VTK等一些编程技巧
- QT使用中的一些技巧
- 纯手工自己积累的一些小的技巧
- Qt界面的一些技巧和实现笔记
- QT界面(控件)相关设计的一些技巧总结
- Qt界面的一些技巧和实现笔记
- CreateThread的用法及在Qt等GUI开发中使用CreateThread的一些技巧
- spring中的一些技巧积累
- Qt使用的一些技巧(未完待续。。。)
- Mac操作积累的一些技巧-陆续增加中
- QT界面(控件)相关设计的一些技巧总结(转)
- Qt的一些样式技巧
- 一些Qt技巧
- 【转载】合成26条军规-高手做广告7-8年,其中积累的一些技巧