QT——设置窗口的固定大小、QProcess、定时器事件、QString::arg、系统时间、QPixmap 和 QImage 区别
2014-05-24 00:25
651 查看
从QT开始,曾经的知识剩多少,想起哪,捡哪,看见哪,记录哪~
=========================================================
1、设置窗口的固定大小(两种方法)
1)this->setMaximumSize(400, 300);
this->setMinimumSize(400, 300);
2)this->setFixedSize(
this->width
(),this->height
())
=========================================================
2、在Linux中可以通过
system 直接启动脚本或者应用程序进程,但是拿不到任何这个新进程的任何新东西,即失去了对该进程的控制权。 但是QT提供 QProcess 可以通过返回的指针拿到该进程的控制权。
Example:
QProcess *myProcess;
----------------------------------------------------------
myProcess=
new QProcess ;
connect(myProcess,
SIGNAL(readyReadStandardOutput()),
this, SLOT(showText()));
----------------------------------------------------------
void Widget::showText(){ /*
SLOT */
QString output =
QTextCodec::codecForLocale()->toUnicode(myProcess->readAllStandardOutput());
ui->textEdit->setText( output );
}
小结:QProcess
对象必须在有输出信号时,才能读取 Process 返回的数据。
也可以通过如下方式使用:
QProcess *process
= new QProcess (0);
process->start("ipconfig");
process->waitForStarted();
while( process->waitForFinished() )
{
QString result=QString::fromLocal8Bit(process->readAllStandardOutput());
ui->textBrowser->setText( result );
}
=========================================================
3、void QTimer::timerEvent(QTimerEvent * event) [virtual protected] /* 定时器事件 */
int QTimerEvent::timerId() const
/*返回定时器句柄,从“1”开始 */
void MainWindow::timerEvent(QTimerEvent *event)
{
switch(event->timerId())
{
case 1 : break;
case 2 : break;
case 3 : break;
}
}
=========================================================
4、QString QString::arg(const QString & a, int fieldWidth = 0, QChar fillChar = QLatin1Char( ' ' )) const
QString
i; // current file's number
QString total; // number of files to process
QString fileName; // current file's name
QString status =
QString("Processing file %1 of %2: %3").arg(i).arg(total).arg(fileName);
--------------------------------------------------------
QString arg(int a, int fieldWidth = 0, int base = 10/* 进制
*/, QChar fillChar = QLatin1Char( ' ' )) const
=========================================================
5、获取系统时间(QTime
只能获取时间、QDateTime包括年月日)
QDateTime time =
QDateTime::currentDateTime();
QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd");
=========================================================
6、QPixmap
和 QImage 区别
1)QPixmap 是专门为绘图而生,针对屏幕显示而最佳化设计。
QPixmap 依赖于所在的平台的绘图引擎,故例如反锯齿等一些效果在不同的平台上可能会有不同的显示效果,QImage 使用Qt自身的绘图引擎,可在不同平台上具有相同的显示效果。
1.X11, Mac 以及 Symbian平台上,QPixmap 是存储在服务器端,和硬件相关;而
QImage 则是存储在客户端,独立于硬件的。 2.在Windows平台上,QPixmap 和 QImage 都是存储在客户端,并不使用任何的GDI(图形设备接口)资源。
----------------------------------------------------------
2)QImage 则是为I/O而生,可以访问图像的像素或修改图像像素/*图像处理*/,或者借助于 QPainter来操作像素。
1.QImage 是独立于硬件的,也是一种 QPaintDevice,可以同时被另一个线程访问,故可以在另一个线程中对其进行绘制,而不需要在GUI
线程中处理,使用这一方式可以很大幅度提高UI响应速度。
-----------------------------------------------------------
3)因此当图片较大时,可以先通过QImage 将图片加载进来,如果直接用 QPixmap 加载会占用很大的内存,最后转换成 QPixmap 进行显示
/ 绘制。
=========================================================
1、设置窗口的固定大小(两种方法)
1)this->setMaximumSize(400, 300);
this->setMinimumSize(400, 300);
2)this->setFixedSize(
this->width
(),this->height
())
=========================================================
2、在Linux中可以通过
system 直接启动脚本或者应用程序进程,但是拿不到任何这个新进程的任何新东西,即失去了对该进程的控制权。 但是QT提供 QProcess 可以通过返回的指针拿到该进程的控制权。
Example:
QProcess *myProcess;
----------------------------------------------------------
myProcess=
new QProcess ;
connect(myProcess,
SIGNAL(readyReadStandardOutput()),
this, SLOT(showText()));
----------------------------------------------------------
void Widget::showText(){ /*
SLOT */
QString output =
QTextCodec::codecForLocale()->toUnicode(myProcess->readAllStandardOutput());
ui->textEdit->setText( output );
}
小结:QProcess
对象必须在有输出信号时,才能读取 Process 返回的数据。
也可以通过如下方式使用:
QProcess *process
= new QProcess (0);
process->start("ipconfig");
process->waitForStarted();
while( process->waitForFinished() )
{
QString result=QString::fromLocal8Bit(process->readAllStandardOutput());
ui->textBrowser->setText( result );
}
=========================================================
3、void QTimer::timerEvent(QTimerEvent * event) [virtual protected] /* 定时器事件 */
int QTimerEvent::timerId() const
/*返回定时器句柄,从“1”开始 */
void MainWindow::timerEvent(QTimerEvent *event)
{
switch(event->timerId())
{
case 1 : break;
case 2 : break;
case 3 : break;
}
}
=========================================================
4、QString QString::arg(const QString & a, int fieldWidth = 0, QChar fillChar = QLatin1Char( ' ' )) const
QString
i; // current file's number
QString total; // number of files to process
QString fileName; // current file's name
QString status =
QString("Processing file %1 of %2: %3").arg(i).arg(total).arg(fileName);
--------------------------------------------------------
QString arg(int a, int fieldWidth = 0, int base = 10/* 进制
*/, QChar fillChar = QLatin1Char( ' ' )) const
=========================================================
5、获取系统时间(QTime
只能获取时间、QDateTime包括年月日)
QDateTime time =
QDateTime::currentDateTime();
QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd");
=========================================================
6、QPixmap
和 QImage 区别
1)QPixmap 是专门为绘图而生,针对屏幕显示而最佳化设计。
QPixmap 依赖于所在的平台的绘图引擎,故例如反锯齿等一些效果在不同的平台上可能会有不同的显示效果,QImage 使用Qt自身的绘图引擎,可在不同平台上具有相同的显示效果。
1.X11, Mac 以及 Symbian平台上,QPixmap 是存储在服务器端,和硬件相关;而
QImage 则是存储在客户端,独立于硬件的。 2.在Windows平台上,QPixmap 和 QImage 都是存储在客户端,并不使用任何的GDI(图形设备接口)资源。
----------------------------------------------------------
2)QImage 则是为I/O而生,可以访问图像的像素或修改图像像素/*图像处理*/,或者借助于 QPainter来操作像素。
1.QImage 是独立于硬件的,也是一种 QPaintDevice,可以同时被另一个线程访问,故可以在另一个线程中对其进行绘制,而不需要在GUI
线程中处理,使用这一方式可以很大幅度提高UI响应速度。
-----------------------------------------------------------
3)因此当图片较大时,可以先通过QImage 将图片加载进来,如果直接用 QPixmap 加载会占用很大的内存,最后转换成 QPixmap 进行显示
/ 绘制。
相关文章推荐
- QT 设置为固定大小窗口
- QT 设置为固定大小窗口
- 在Qt 4中如何固定窗口的大小
- Qt设置系统时间
- Qt下设置停靠窗口的大小
- qt固定窗口大小
- QT 事件处理 KeyPressEvent 和 定时器时间 Timer
- C# 定时器事件。(设置时间间隔,间歇性执行某一函数,控制台程序)
- qt设置对话框或控件为固定大小
- qt4 设置系统日期 时间,set time date, set system date time
- QT获取系统时间以及设置日期格式
- Qt4 设置系统日期时间
- 在Qt中如何固定窗口的大小?
- Qt窗口屏幕居中显示以及设置大小
- Qt中设置系统时间,调用system()函数
- QT 设置系统时间
- Java 设置窗口系统关闭按钮的事件响应
- QT 设置系统时间
- QT 中 界面中消息的停留时间解决方案 以及 label 中字体大小和换行设置
- QT 事件处理 KeyPressEvent 和 定时器时间 Timer