唔。有趣的。以下代码用于测试您的问题,但找不到任何问题。它按原样工作。(在 Mac OSX 上使用 Qt 4.8.2)。代码是自包含的。只需将其作为 main.cpp 构建应用程序,然后单击显示和隐藏按钮进行测试。
#include <QtGui>
class FramedWidget : public QFrame
{
public:
FramedWidget(QWidget* inner, QWidget* parent=0)
: QFrame(parent)
{
setFrameStyle(QFrame::Panel | QFrame::Sunken);
QVBoxLayout* lay = new QVBoxLayout(this);
lay->setContentsMargins(0,0,0,0);
lay->setSpacing(0);
lay->addWidget(inner);
}
};
class LayoutWidget : public QSplitter
{
public:
LayoutWidget(QWidget* parent=0)
: QSplitter(parent)
{
QTableWidget* table = new QTableWidget;
m_button = new QPushButton("Testing...");
QPushButton* showButton = new QPushButton("Show");
QPushButton* hideButton = new QPushButton("Hide");
connect(showButton, SIGNAL(clicked()),
m_button, SLOT(show()));
connect(hideButton, SIGNAL(clicked()),
m_button, SLOT(hide()));
QWidget* tester = new QWidget;
QVBoxLayout* testerLay = new QVBoxLayout(tester);
testerLay->addWidget(table);
testerLay->addWidget(m_button);
QWidget* controller = new QWidget;
QVBoxLayout* controllerLay = new QVBoxLayout(controller);
controllerLay->addWidget(showButton);
controllerLay->addWidget(hideButton);
controllerLay->addWidget(new QTextEdit);
this->addWidget(new FramedWidget(controller));
this->addWidget(new FramedWidget(tester));
}
protected:
QPushButton* m_button;
};
int main(int argc, char** argv)
{
QApplication app(argc, argv);
LayoutWidget* editor = new LayoutWidget;
editor->show();
editor->raise();
return app.exec();
}