首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QGridlayout更改行的高度

QGridlayout更改行的高度
EN

Stack Overflow用户
提问于 2010-09-30 16:08:06
回答 2查看 2.9K关注 0票数 2

我对QGridLayout有点问题。我的布局的一行包含一个正常隐藏的元素(QProgressbar)。当有一些进展要报告时,我会调用show on it。问题是,当我在QProgressbar上调用show时,包含它的行上方的行将稍微调整高度(1-3px)。因此,整个布局做了一点“跳转”,看起来很丑陋。

我已经为包含QProgressbar的行提供了一个minimalRowHeight,它比QProgressbar的高度大得多,但是在show()中,该行的高度仍然会增加。

我已经附上了我的程序的一个非常简单的版本,证明了这个问题。有人能给我一个提示吗?那里发生了什么事?

标题:

代码语言:javascript
复制
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QLineEdit>
#include <QtWebKit/QWebView>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);

private:
    QLineEdit* input;
    QWebView *webview;

private slots:
    void slotLoadButton();
};

#endif // MAINWINDOW_H

来源:#include "mainwindow.h“

代码语言:javascript
复制
#include <QProgressBar>
#include <QPushButton>
#include <QGridLayout>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    QGridLayout *grid = new QGridLayout;

    input = new QLineEdit;

    QPushButton *loadButton = new QPushButton("load");
    connect(loadButton, SIGNAL(clicked()),
            this, SLOT(slotLoadButton()));

    webview = new QWebView;
    QProgressBar *progress = new QProgressBar;
    progress->setFixedHeight(25);
    progress->hide();

    connect(webview, SIGNAL(loadStarted()),
            progress, SLOT(show()));

    connect(webview, SIGNAL(loadProgress(int)),
            progress, SLOT(setValue(int)));

    connect(webview, SIGNAL(loadFinished(bool)),
            progress, SLOT(hide()));

    grid->addWidget(input, 0, 0);
    grid->addWidget(loadButton, 0, 1);
    grid->addWidget(webview, 1, 0, 1, -1);
    grid->setRowMinimumHeight(2, 35);
    grid->addWidget(progress, 2, 1);

    QWidget* widget = new QWidget;
    widget->setLayout(grid);
    setCentralWidget(widget);
}

void MainWindow::slotLoadButton()
{
    QUrl url = input->text();
    webview->load(url);
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-09-30 23:42:48

这可能是由布局的垂直间距和/或页边距引起的。您应该尝试使用这些属性。

票数 0
EN

Stack Overflow用户

发布于 2010-09-30 23:29:23

这看起来像是Qt中的一个bug。试试reporting it

这是一种解决方法:

代码语言:javascript
复制
//grid->addWidget(progress, 2, 1);
QHBoxLayout *l = new QHBoxLayout;
l->addWidget(progress);
QWidget *w = new QWidget;
w->setLayout(l);
grid->addWidget(w, 2, 1);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3828846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档