各位好,我在学习使用QPainter类,遇到问题如下:
目的: 想在弹出的对话框DlgImageView中显示一块背景为黑色,绘有一些绿色连线的图.
代码:
DlgImageView::DlgImageView( QWidget* parent,  const char* name, bool modal, WFlags fl )    : QDialog( parent, name, modal, fl )
{
       ...
       QVBoxLayout *vb = new QVBoxLayout( this, 3 );       
       vb->addWidget( new QLabel( "Draw Image Test:", this ) );
       //add Read Image View
       QWidget *imageRead = new QWidget(this);
       imageRead->setMinimumHeight( 30 );
       imageRead->setBackgroundColor( black );
       setMinimumWidth( points );              
       QPainter p(imageRead);
       //draw some lines to test
       p.setPen( red );
       p.drawLine( 0, 25, 10, 25 );
       p.drawText( 0, 25, "10" );
       p.drawText( 0, 23, "0" );
       p.setPen( green );
       for ( int i = 0; i < points-1; i++ ) 
       {
              int y1 = i*5;
              int y2 = (i+1)*5;
              p.drawLine(i, y1, (i+1), y2);
       }
       vb->addWidget( imageRead, 100 );
       vb->addWidget( new QLabel( "The end", this ) );
}
结果: 黑色背景可以显示,但上面没有线条可以显示.见附图.
问题: 1. 我的代码错在哪里?
      2. 语句 vb->addWidget( imageRead, 100 ) 中的参数"100"代表stretch. 
     关于stretch的解释是
     "Widgets are normally created without any stretch factor set. When they are laid out in a layout the widgets are given a share of space in accordance with their QWidget::sizePolicy() or their minimum size hint whichever is the greater. Stretch factors are used to change how much space widgets are given in proportion to one another. "
     但我还不太明白stretch的作用.像下面两行代码
     vb->addWidget( widget1, 100 )
     vb->addWidget( widget2, 10 )
     是否表示widget1占用的space和widget2的space的比例是100:10呢?如果是,那么那些没有设置stretch的widget占用的space又怎么算呢?
谢谢!
[ 此贴被mudfish在2005-11-14 15:51重新编辑 ]