我有QGridLayout的问题。我的布局的一行包含一个常规隐藏的元素(QProgressbar)。当我有一些进展来报告我呼吁节目。问题是,当我在QProgressbar上调用show时,包含它的行上方的行将在高度(1-3 px)中稍微调整大小。所以整个布局做了一些看起来很难看的“跳跃”。QGridlayout更改行的高度
我已经给包含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);
}
btw。任何调试提示对我也是有用的。 – 2010-09-30 15:03:11