2010-09-30 112 views
2

我有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); 
} 
+0

btw。任何調試提示對我也是有用的。 – 2010-09-30 15:03:11

回答

0

這可能是由垂直間隔和/或佈局的邊緣引起的。你應該嘗試玩這些屬性。

0

這看起來像在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);