• 6437阅读
  • 2回复

请教窗口布局 [复制链接]

上一主题 下一主题
离线my253629725
 

只看楼主 正序阅读 楼主  发表于: 2008-11-13
— 本帖被 XChinux 执行加亮操作(2008-11-30) —
该程序的父类是QDialog,实现一个全屏的登录窗口,现在的布局效果是三行平均布置在该全屏窗口中,我该如何才能将这些控件放置在该全屏窗口的中上部分
#include "login.h"
Login::Login(QWidget *parent, Qt::WFlags flags)
    : QDialog(parent, flags)
{
    nameLabel = new QLabel(QTextCodec::codecForLocale()->toUnicode("用户名:"));
    nameEdit = new QLineEdit;
    nameLabel->setBuddy(nameEdit);
    nameEdit->actions();
    passwdLabel = new QLabel(QTextCodec::codecForLocale()->toUnicode("密  码:"));
    passwdEdit = new QLineEdit;
    passwdLabel->setBuddy(passwdEdit);

    loginButton = new QPushButton(QTextCodec::codecForLocale()->toUnicode("确  定"));
    loginButton->setDefault(true);
    loginButton->setEnabled(false);

    poweroffButton = new QPushButton(QTextCodec::codecForLocale()->toUnicode("关  机"));
    poweroffButton->setDefault(true);
    poweroffButton->setEnabled(true);

    QHBoxLayout *topLayout = new QHBoxLayout;
    topLayout->addWidget(nameLabel);
    topLayout->addWidget(nameEdit);

    QHBoxLayout *middleLayout = new QHBoxLayout;
    middleLayout->addWidget(passwdLabel);
    middleLayout->addWidget(passwdEdit);

    QHBoxLayout *bottomLayout = new QHBoxLayout;
    bottomLayout->addWidget(loginButton);
    bottomLayout->addWidget(poweroffButton);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(topLayout);
    mainLayout->addLayout(middleLayout);
    mainLayout->addLayout(bottomLayout);
    setLayout(mainLayout);
    ui.setupUi(this);
   
}

Login::~Login()
{

}

bool Login::loginServer(const QString *name,const QString *passwd){
    return false;
}

void Login::enableLoginButton(const QString &name,const QString &passwd){
}
离线aven152273

只看该作者 2楼 发表于: 2008-11-14
当然也可以自己固定大小和坐标实现。就是麻烦了点

调用setGeometry( QRect( x ,y,width,heigt ) ); 固定大小和坐标
条用setFixedSize (width,height);来固定大小
离线vrcats
只看该作者 1楼 发表于: 2008-11-14
下头加一个QSpacerItem,然后设置上头的SizePolicy让它不自由扩大。你可以在Qt Designer里头先试好了再动手写。
快速回复
限100 字节
 
上一个 下一个