我对QGridLayout有点问题。我的布局的一行包含一个正常隐藏的元素(QProgressbar)。当有一些进展要报告时,我会调用show on it。问题是,当我在QProgressbar上调用show时,包含它的行上方的行将稍微调整高度(1-3px)。因此,整个布局做了一点“跳转”,看起来很丑陋。
我已经为包含QProgressbar的行提供了一个minimalRowHeight,它比QProgressbar的高度大得多,但是在show()中,该行的高度仍然会增加。
我已经附上了我的程序的一个非常简单的版本,证明了这个问题。有人能给我一个提示吗?那里发生了什么事?
标题:
#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“
#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);
}发布于 2010-09-30 23:42:48
这可能是由布局的垂直间距和/或页边距引起的。您应该尝试使用这些属性。
发布于 2010-09-30 23:29:23
这看起来像是Qt中的一个bug。试试reporting it
这是一种解决方法:
//grid->addWidget(progress, 2, 1);
QHBoxLayout *l = new QHBoxLayout;
l->addWidget(progress);
QWidget *w = new QWidget;
w->setLayout(l);
grid->addWidget(w, 2, 1);https://stackoverflow.com/questions/3828846
复制相似问题