QTable Viewはtooltipと設定ログを表示します。

3300 ワード

テキスト
http://www.cppblog.com/biao/archive/2009/08/07/92577.html
狂奔するカタツムリはとても力があります。
1.QTableViewを設定すると、マウスの追跡が有効になります。
ui->テーブルビュー->set Mouse Tracking(true)
2.QTableViewのentered信号と接続する:
connect(ui->テーブルビュー、SIGNAL(entered(QModelIndex)
this、SLOT(showToolTip(QModelIndex);
3.不正関数:
void Widget:showToolTip(const QModelIndex&index)
if(!index.isValid(){
qDebug()<「Invalid index」;
return;
)
QToolTip::showText(QCurrsor:pos()、index.data().toString()+「goto hell」)
)
QCurrsor::pos():マウスの位置を返します。
4.QTableViewの自分の持っている関数を使って、関数の原型は以下の通りです。
イ.table Widget->resize Column ToContens(0)
最初の列を内容に応じて列の幅を自動的に調整します。
内容に応じて列の幅を自動調整します。
void QTable View:resize Column ToContents(int column)[slot]
Resizes the given column based on the size hints of the delegate used to render rech item in the column.
内容に応じて列の幅を自動調整します。
void QTable View:resize ColumnstoContents()[slot]
Resizes all columns based on the size hints of the delegate used to render each item in the columns.
内容に応じて、行の高さを自動調整します。
void QTable View:resize RowToContents(int row)[sloot]
Resizes the given row based on the size hints of the delegate used to render each item in the row.
内容に応じて行の高さを自動調整します。
void QTable View:resize Rows ToContets()[slot]
Resizes all rows based on the size hints of the delegate used to render each item in the rows.
設定日誌:使ってみましたが、時間がないような気がします。後で時間があったら、自分でコードを入れて改善してください。

#include <QtDebug>
#include <QFile>
#include <QTextStream>

void customMessageHandler(QtMsgType type, const char *msg)
{
        QString txt;
        switch (type) {
        //      
        case QtDebugMsg:
                txt = QString("Debug: %1").arg(msg);
                break;

        //   warning  
        case QtWarningMsg:
                txt = QString("Warning: %1").arg(msg);
        break;
        //      
        case QtCriticalMsg:
                txt = QString("Critical: %1").arg(msg);
        break;
        //      
        case QtFatalMsg:
                txt = QString("Fatal: %1").arg(msg);
                abort();
        }

        QFile outFile("debuglog.txt");
        outFile.open(QIODevice::WriteOnly | QIODevice::Append);
        QTextStream ts(&outFile);
        ts << txt << endl;
}

int main( int argc, char * argv[] )
{
        QApplication app( argc, argv );

        //      MsgHandler
        qInstallMsgHandler(customMessageHandler);        
        
        //                   ,            
        qDebug("This is a debug message at thisisqt.com");
        qWarning("This is a warning message  at thisisqt.com");
        qCritical("This is a critical message  at thisisqt.com");
        qFatal("This is a fatal message at thisisqt.com");

        return app.exec();
}