QT——设置窗口的固定大小、QProcess、定时器事件、QString::arg、系统时间、QPixmap 和 QImage 区别

从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 进行显示 / 绘制。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值