我正在 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 类时,窗口完全是空白的!希望有人可以帮助我。谢谢你。
干杯,