2

Я создаю QWidget. Накладаю на нево QVBoxLayout. До QVBoxLayout додаю QLineEdit. Размер QLineEdit установляю таков как QWidget. При исполнении програми QLineEdit есть обрезаный. Почему?

class functionSticker : public QWidget
{
    Q_OBJECT
    QTextEdit* text_description;


public:
    explicit functionSticker(const QString& text, QWidget *parent = 0 );
public slots:
    void resizeFrame();
};
functionSticker::functionSticker(const QString& text, QWidget *parent) :
    QWidget(parent),
    text_description(new QTextEdit)
{
    text_description->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setLayout(new QVBoxLayout);
    layout()->setSpacing(0);
    layout()->addWidget(text_description);
    text_description->setText(text);
    setFixedHeight(100);
    show();
    connect(text_description, SIGNAL(textChanged()), this,SLOT(resizeFrame()));
}

void functionSticker::resizeFrame()
{
    int height = text_description->document()->size().height();
    setFixedHeight(height);
    text_description->setFixedHeight( height );
    updateGeometry();
}
0

1 ответ 1

3

Смотрите внимательно какому виджету какие размеры вы устанавливаете.

При использовании layout'ов родительский виджет сам подстроит свой размер под размеры содержимого.

FunctionSticker::FunctionSticker(const QString& text, QWidget *parent) :
    QWidget(parent),
    text_description(new QTextEdit)
{
    text_description->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setLayout(new QVBoxLayout);
    layout()->setSpacing(0);
    layout()->addWidget(text_description);
    text_description->setText(text);
    text_description->setFixedHeight(100); // !<--------------
    show();
    connect(text_description, SIGNAL(textChanged()), this,SLOT(resizeFrame()));
}

void FunctionSticker::resizeFrame()
{
    int height = text_description->document()->size().height();
//    setFixedHeight(height);  // !<--------------
    text_description->setFixedHeight( height );
    updateGeometry();
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.