[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Layout problem in QLabel with rich text
From:       Michael Goffioul <goffioul () imec ! be>
Date:       2001-11-13 8:38:45
[Download RAW message or body]

Hi,

As far as I remember, since rich text has been introduced in Qt, I'm
experiencing layout problems with QLabel containing rich text. The
problem looks like when the layout computes the widget size, it uses
one height value for the QLabel, but on showing, the QLabel uses
another height value, usually larger, producing clipping effect.
To illustrate this, I wrote this simple program:


#include <qlabel.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <qframe.h>
#include <qlistview.h>
#include <qapplication.h>

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

        QWidget *mainw = new QWidget;
        QLabel  *label = new QLabel(mainw);
        QPushButton     *btn = new QPushButton( "Push Me To Exit", mainw);
        QFrame  *frame = new QFrame(mainw);
        frame->setFrameStyle(QFrame::HLine|QFrame::Sunken);
        frame->setLineWidth(1);
        QListView       *list = new QListView(mainw);
        list->addColumn("Column 1");
        new QListViewItem(list, "Item 1");
        new QListViewItem(new QListViewItem(list, "Item 2"), "Item 3");
        QObject::connect(btn, SIGNAL(clicked()), &app, SLOT(quit()));

        label->setText("<b>Label Text</b>");

        QVBoxLayout     *lay0 = new QVBoxLayout(mainw, 10, 10);
        QHBoxLayout     *lay1 = new QHBoxLayout(0, 0, 0);
        lay0->addWidget(label);
        lay0->addWidget(frame);
        lay0->addWidget(list);
        lay0->addLayout(lay1);
        lay1->addStretch(1);
        lay1->addWidget(btn);

        mainw->show();
        app.setMainWidget(mainw);

        return app.exec();
}

Reduce the widget height to its minimum, you'll notice that the button
is clipped. If you remove the rich tags from its string (the <b> tags),
then everything is OK.

Bye.
Michael.

-- 
------------------------------------------------------------------
Michael Goffioul		IMEC-DESICS-MIRA
e-mail: goffioul@imec.be	(Mixed-Signal and RF Applications)
Tel:    +32/16/28-8510		Kapeldreef, 75
Fax:    +32/16/28-1515		3001 HEVERLEE, BELGIUM
------------------------------------------------------------------

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic