天嵌 ARM开发社区

 找回密码
 注册
查看: 2676|回复: 6

请问:在QTable中的一个表格中可以插入图片吗

[复制链接]
testh 发表于 2010-8-31 09:14:09 | 显示全部楼层 |阅读模式
我想把一个图片插到QTable中,但是使用
QTable *tlb=new QTable(this);
QPixmap testimg("/opt/test.png");
tlb->setPixmap(0,0,testimg);

在编译时显示:
error: no matching function for call to 'QTable::setPixmap(int, int, QPixmap*&)
我查看了include/qtable.h中的setPixmap的原型为:
virtual void setPixmap( int row, int col, const QPixmap &pix );
为什么在编译的时候过不去,请教大家,谢谢。
天嵌_support1 发表于 2010-8-31 10:50:46 | 显示全部楼层
1# testh


你的头文件呢? 你借鉴一下这个例子:

Implementation:

/****************************************************************************
** $Id: qt/main.cpp   3.3.7   edited Aug 31 2005 $
**
** Copyright (C) 1992-2005 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include <qapplication.h>
#include <qtable.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qstringlist.h>

// Qt logo: static const char *qtlogo_xpm[]
#include "qtlogo.xpm"

// Table size

const int numRows = 30;
const int numCols = 10;

// The program starts here.

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

    QTable table( numRows, numCols );

    QHeader *header = table.horizontalHeader();
    header->setLabel( 0, QObject::tr( "Tiny" ), 40 );
    header->setLabel( 1, QObject::tr( "Checkboxes" ) );
    header->setLabel( 5, QObject::tr( "Combos" ) );
    table.setColumnMovingEnabled(TRUE);

    QImage img( qtlogo_xpm );
    QPixmap pix = img.scaleHeight( table.rowHeight(3) );
    table.setPixmap( 3, 2, pix );
    table.setText( 3, 2, "A Pixmap" );

    QStringList comboEntries;
    comboEntries << "one" << "two" << "three" << "four";

    for ( int i = 0; i < numRows; ++i ){
        QComboTableItem * item = new QComboTableItem( &table, comboEntries, FALSE );
        item->setCurrentItem( i % 4 );
        table.setItem( i, 5, item );
    }
    for ( int j = 0; j < numRows; ++j )
        table.setItem( j, 1, new QCheckTableItem( &table, "Check me" ) );

    app.setMainWidget( &table );
    table.show();
    return app.exec();
}
回复

使用道具 举报

 楼主| testh 发表于 2010-9-1 16:34:02 | 显示全部楼层
已经可以了,谢谢
回复

使用道具 举报

天嵌_support1 发表于 2010-9-1 17:09:22 | 显示全部楼层
3# testh


testh 可以的话,尽量把你解决的过程和结果告诉大家。
让后来遇到相同问题的人可以得到学习。
谢谢你
回复

使用道具 举报

 楼主| testh 发表于 2010-9-2 10:49:18 | 显示全部楼层
没问题,昨天没来得及细写。
    Table2 = new QTable( this, "Table2" );
    Table2->setGeometry( QRect( 18, 220, 762, 232 ) );
    Table2->setNumRows( 4 );                //定义行
    Table2->setNumCols( 5 );                //定义列


    QHeader *verti=Table2->verticalHeader();        //获取列的标题头
    QHeader *hori=Table2->horizontalHeader();         //获取行的标题头


        QPixmap name_img("/opt/name.png");        //载入一个png图片
        QIconSet name_icon(name_img);                //将载入的图片放在QIconSet中
        hori->setLabel(0,name_icon,0);                //最后将name_icon放到Table的Label中

使用这种方法可以间接的实现汉化,将中文做成图片,然后将图片签到Tabel的Label中,注意字的图片的背景颜色需要与Tabel的颜色一样
回复

使用道具 举报

wiii 发表于 2010-11-25 10:34:32 | 显示全部楼层
5# testh


你好。。你知道在Table中添加CheckBox吗?就是QCheckTableItem怎么用的?
回复

使用道具 举报

wiii 发表于 2010-11-25 10:41:08 | 显示全部楼层
2# embedsky_lxt


版主,你给的例子在帮助文件中我见到过,我用的是天谴的qtopia-2.2.0,使用
table.setItem( j, 1, new QCheckTableItem( &table, "Check me" ) );
是不行的,我试了许多下都还是不行啊?我就是想在Table中添加CheckBox这控件?请教版主。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2025-5-2 17:48 , Processed in 2.032040 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表