views:

77

answers:

0

Hi Geeks,

In Qt application , I am using a QTabWidget where its first tab points to a QWidget which is a login form. Pasting the code for login widget.

#include "conn.h"
#include <QVariant>
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
//#include <QGridLayout>
#include <QVBoxLayout>
#include <QHeaderView>
#include <QSpacerItem>
#include <QWidget>



connWidget::connWidget(QWidget *parent)
    :QWidget(parent)
{
    //QGridLayout *grid = new QGridLayout(this);
    loginWgt = new QWidget(this);
    loginWgt->setObjectName(QString::fromUtf8("loginWgt"));
    //loginWgt->setGeometry(QRect(80, 100, 297, 124));
    //loginWgt->setGeometry(QRect((this->width()/2)-150, (this->height()/2)-113, 300, 126));
    //qDebug("width = %d height = %d ",this->width(),this->height());
    loginWgt->setGeometry(QRect(250,200 , 297, 124));
    //QVBoxLayout *lytVBox = new QVBoxLayout(this);


    lytGrid = new  QGridLayout(loginWgt);
    lytGrid->setSpacing(6);
    lytGrid->setContentsMargins(11, 11, 11, 11);
    lytGrid->setObjectName(QString::fromUtf8("lytGrid"));
    lytGrid->setContentsMargins(0, 0, 0, 0);

    lblUname = new QLabel(loginWgt);
    lblUname->setObjectName(QString::fromUtf8("lblUname"));
    QFont font;
    font.setPointSize(8);
    lblUname->setFont(font);
    lblUname->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    lblUname->setText("Username");
    lytGrid->addWidget(lblUname, 0, 0, 1, 1);

    leUname = new QLineEdit(loginWgt);
    leUname->setObjectName(QString::fromUtf8("leUname"));
    lytGrid->addWidget(leUname, 0, 1, 1, 2);

    lblPwd = new QLabel(loginWgt);
    lblPwd->setObjectName(QString::fromUtf8("lblPwd"));
    lblPwd->setFont(font);
    lblPwd->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    lblPwd->setText("Password");
    lytGrid->addWidget(lblPwd, 1, 0, 1, 1);

    lePwd = new QLineEdit(loginWgt);
    lePwd->setObjectName(QString::fromUtf8("lePwd"));
    lytGrid->addWidget(lePwd, 1, 1, 1, 2);

    btnOk = new QPushButton(loginWgt);
    btnOk->setObjectName(QString::fromUtf8("btnOk"));
    btnOk->setFont(font);
    btnOk->setText("OK");
    lytGrid->addWidget(btnOk, 2, 1, 1, 1);

    btnCancel = new QPushButton(loginWgt);
    btnCancel->setObjectName(QString::fromUtf8("btnCancel"));
    btnCancel->setFont(font);
    btnCancel->setText("CANCEL");
    lytGrid->addWidget(btnCancel, 2, 2, 1, 1);

    //lytVBox->addLayout(lytGrid);

}

This I want to position the login form at the centre of area available for current. I dont want to provide the absolute position like I have done in the above code. I want something which will not constrained by any screens or size of the mainWindow also. Its position should be always center of tabWidget area.

I am afraid i could explain the problem clearly. But If you want any further clarification I can provide.