QT 常見設置

一、Qt4.7添加背景
 QPixmap pixmap(":/new/prefix1/1.jpg"); 
    QPalette palette;
    palette.setBrush(backgroundRole(), QBrush(pixmap));
    setPalette(palette);


文件1.jpg在Resource data中的/new/prefix1/ 目錄;

二、隱藏標題欄
  weather::setWindowFlags(Qt::FramelessWindowHint); //隱藏;

問:如何用QT創建一個不帶標題欄的窗口?就象啓動畫面一樣的?
答:loginDlg::setWindowFlags(Qt::FramelessWindowHint)即可;

// Qt::WStyle_Customize|Qt::WStyle_NoBorder
Qt::WStyle_NoBorder FramelessWindowHint Use Qt::FramelessWindowHint instead.

三、設置窗口大小樣式,有四種選擇

w.show();                    實際大小

w.showEvent()                自定義大小

w.showFullScreen();          全屏

w.showMaximized();           最大化

w.showMinimized();           最小化

w.showNormal();              正常

四、編譯安裝qt-4.6.2 嵌入式版 裏面沒有phonon的庫 怎麼辦
加上編譯選項 -phonon -phonon-backend 就把phonon庫編譯進去了.

 五、字體格式設置
   
    QTextCharFormat TCForm;
    QFont fon2;
  
    // fon1.setFontUnderline(1);

    fon2.setBold(1);       //設爲粗體
    TCForm.setFont(fon2);  //配置QTextCharFormat
    ui->calendarWidget->setDateTextFormat(date1,TCForm);

   像QTextCharFormat ,QFont ,Widget這些類,可以直接用TCForm.setFont(fon2); ui->是名空間。
 
 六、設置開機啓動qt程序
    在/bin/qt4 裏面有開機啓動的腳本
    注意要啓動的文件在檢索附加文件時和在控制檯啓動有不同,比如在fopen("qidong.txt");qidong.txt在/opt/qt-4.7/bin/下面。
    在控制檯啓動時而且程序在/opt/qt-4.7/bin/下面,則會直接檢索/opt/qt-4.7/bin/目錄。
    在開機自啓動時,則會檢索根目錄 / ,而不是/opt/qt-4.7/bin/;這樣就有可能造成程序不能啓動。所以在寫程序是應該寫成
    fopen("/opt/qt-4.7/bin/qidong.txt");
       
   
    vi /bin/qt4
   
#!/bin/sh

echo Start Qt-4.7 > /dev/tq2440_serial0
export set TSLIB_TSDEVICE=/dev/event0
export set TSLIB_CALIBFILE=/etc/pointercal
export set TSLIB_CONFFILE=/etc/ts.conf
export set TSLIB_PLUGINDIR=/lib/ts
export set HOME=/root
export set QTDIR=/opt/qt-4.7
export set QPEDIR=/opt/qt-4.7
export set QTDIR1=/sbin
export set QWS_DISPLAY="LinuxFB:/dev/fb0"
export set QWS_DISPLAY="LinuxFB:mmWidth130:mmHeight100:0"
export s$QPEDIR/bin/home6 -qws 1> /dev/null 2>/dev/null
export s$QPEDIR/bin/home6 -qwsLIB:/dev/event0"

export set QT_QWS_FONTDIR=$QTDIR/lib/fonts/
export set PATH=$QPEDIR/bin:$PATH
export set LD_LIBRARY_PATH=$QTDIR/lib:$QPEDIR/plugins/imageformats:$LD_LIBRARY_P

                                                                               
if [ -f /etc/pointercal ] ; then                                               
        $QPEDIR/bin/home6 -qws 1> /dev/null 2>/dev/null           
        //就在這兩行    加啓動程序        
        $QPEDIR/bin/home6 -qws                                                 
else                                                                           
        ts_calibrate                                                           
#       $QPEDIR/bin/mousecalibration                                           
        $QPEDIR/bin/hello_cn -qws 1> /dev/null 2>/dev/null
fi  

七、qt4的中文顯示問題


1)、去文泉驛官方網http://wenq.org/下載一個字庫回來。裏面有很多字庫,我選擇常用的正黑。正黑字庫文件下載地址是: http://downloads.sourceforge.net/project/wqy/wqy-zenhei/0.8.38%20(Pangu)/wqy-zenhei-0.8.38-1.tar.gz?use_mirror=nchc&18950117

下載回來的文件裏面有這樣一個文件:wqy-zenhei.ttc,將其放到/opt/qt-4.5/lib/fonts裏面,再在主函數裏面修改字庫的ID:
int main(int argc, char *argv[])
{
    QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
  
    QApplication a(argc, argv);
    Widget w;
       
 w.setFont(QFont("wqy-zenhei",14,QFont::Normal));//這行是關鍵,沒有這行是顯示不了中文的。
    w.setWindowTitle(QObject::tr("爲什麼why?"));
    w.show();
     return a.exec
}


 /* QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
   /* QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));*/
    load_etc();
    MainWidget w;*/

發佈了19 篇原創文章 · 獲贊 22 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章