开发者

Qt Widget does not show

I create a class which is a subclass of a QWidget used for painting a image, only for painting a image, named ImageWidget.

When I only create a ImageWidget and call ImageWidget.show(), everything is fine. Then I create another QWidget开发者_如何学编程 subclass like below. At present, only shows the combox and slider, the image does not show. Could someone help me about it?

    MainWindow::MainWindow(QWidget *parent) :
        QWidget(parent)
    {
        imgWidget=new ImageWidget(this);
    fractalTypeLabel=new QLabel(tr("Type"));
    typeCombo=new QComboBox();
    typeCombo->addItem(tr("One"));
    typeCombo->addItem(tr("Two"));
    scalefactorLabel=new QLabel(tr("Scale Factor"));
    scalefactorSlider=new QSlider(Qt::Horizontal);
    scalefactorSlider->setTickInterval(1);
    scalefactorSlider->setTickPosition(QSlider::TicksBelow);

    QVBoxLayout *imageLayout=new QVBoxLayout();
    imageLayout->addWidget(imgWidget);

    QGridLayout *gridLayout=new QGridLayout;
    gridLayout->addWidget(fractalTypeLabel,0,0);
    gridLayout->addWidget(typeCombo,0,1);
    gridLayout->addWidget(scalefactorLabel,1,0);
    gridLayout->addWidget(scalefactorSlider,1,1);

QHBoxLayout *mainLayout=new QHBoxLayout;
    mainLayout->addLayout(imageLayout);
    mainLayout->addLayout(gridLayout);

    this->setLayout(mainLayout);
    }

Best Regards,


Most Likely you are not reporting a size for your widget from sizeHint, in your custom subclass implement virtual QSize sizeHint () const and return something. Your widget will probably show. In the absence of sizeHint the system thinks that your widget can be of size 0x0 and eliminates it from the layout. There are other ways around this by playing with the layout settings. It is slightly non-intuitive ... . You might want to implement some of the other size related functions in from QWidget

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜