我正在使用Qt 4.8.4开发一个应用程序,以下是我的操作:
我将QGridLayout子类化如下:
class Viewer : public QGridLayout
{
Q_OBJECT
...................
private:
// Objects
/// Maximize button object
ViewerGeneric* viewerGeneric;
/// Maximize button object
QPushButton* btnMaximize;
/// Close button object
QPushButton* btnClose;
/// Connect button object
QPushButton* btnConnect;
/// Central viewer layout object
QGridLayout* viewer;
/// Indicates the row position in the main grid
unsigned int row;
/// Indicates the column position in the main grid
unsigned int col;
};
然后在构造函数中我会这样做:
// Create the objects
btnMaximize = new QPushButton("max");
btnClose = new QPushButton("close");
btnConnect = new QPushButton("connect");
// Add the horizontal toolbar
QHBoxLayout* toolbar = new QHBoxLayout();
toolbar->setSizeConstraint(QLayout::SetMinimumSize);
toolbar->addItem(new QSpacerItem(0, 0,
QSizePolicy::Expanding, QSizePolicy::Minimum));
toolbar->addWidget(btnMaximize);
toolbar->addWidget(btnClose);
// Add the 'Connect' button
viewer = new QGridLayout();
viewer->addWidget(btnConnect);
// Add the widgets
this->addItem(toolbar, 0, 0);
this->addItem(viewer, 0, 0, 2);
但是最后,当我在主窗口中展示Viewer类时,窗口完全空白!希望有人能帮助我。谢谢。
祝好,