PDA

View Full Version : GUI not displaying



ToddAtWSU
22nd February 2007, 17:36
I have been trying to get a GUI to display inside Qt 3.3.7 and I have designed it off other classes I have successfully created. But for some reason all I see in this QDialog is the very first item I add to the layout. Here is my code for the constructor and the createGui function. Sorry if there is a typo as my coding machine is not hooked up online so I have to retype all my code to show on here. Thanks for your help!


ScreeningDialog::ScreeningDialog( Configuration *conf, QWidget *parent ) : QDialog( parent )
{
createGui( );
mpConfiguration = config;
mScreeningLocation = mpConfiguration->getScreeningExe( );

setPalette( parent->palette( ) );
}


void ScreeningDialog::createGui( )
{
QWidget *mainWidget = new QWidget( this );
QGridLayout = new QGridLayout( mainWidget );

QLabel *outputDirLabel = new QLabel( tr( "Output Directory:" ), mainWidget );
mpOutputDirLnEd = new QLineEdit( mainWidget );
QPushButton *outputButton = new QPushButton( tr( "Open" ), mainWidget );
connect( outputButton, SIGNAL( clicked( ) ), this, SLOT( openDirPressed( ) ) );

QLabel *confFileLabel = new QLabel( tr( "Configuration File:" ), mainWidget );
mpConfFileLnEd = new QLineEdit( mainWidget );
QPushButton *confButton = new QPushButton( tr( "Open" ), mainWidget );
connect( confButton, SIGNAL( clicked( ) ), this, SLOT( openFilePressed( ) ) );

QGroupBox *methodBox = new QGroupBox( tr( "Method" ), mainWidget );
QVBoxLayout *methodLayout = new QVBoxLayout( methodBox );
QButtonGroup *methodGroup = new QButtonGroup( );
methodGroup->setExclusive( true );
mpWidthCB = new QCheckBox( tr( "Width" ), methodBox );
mpAutoCB = new QCheckBox( tr( "Auto" ), methodBox );

methodGroup->insert( mpWidthCB );
methodGroup->insert( mpAutoCB );

methodLayout->addWidget( mpWidthCB );
methodLayout->addWidget( mpAutoCB );

QPushButton *executeButton = new QPushButton( tr( "Execute" ), mainWidget );
connect( executeButton, SIGNAL( clicked( ) ), this, SLOT( executePressed( ) ) );
QPushButton *cancelButton = new QPushButton( tr( "Cancel" ), mainWidget );
connect( cancelButton, SIGNAL( clicked( ) ), this, SLOT( cancelPressed( ) ) );

mainLayout->addWidget( outputDirLabel, 0, 0 );
mainLayout->addWidget( mpOutputDirLnEd, 0, 1 );
mainLayout->addWidget( outputButton, 0, 2 );
mainLayout->addWidget( confFileLabel, 1, 0 );
mainLayout->addWidget( mpConfFileLnEd, 1, 1 );
mainLayout->addWidget( confButton, 1, 2 );
mainLayout->addWidget( methodBox, 2, 0 );
mainLayout->addWidget( executeButton, 3, 1 );
mainLayout->addWidget( cancelButton, 3, 2 );
}

I cannot figure why the only thing I see when I open the dialog is the label that says "Output Directory:". Thanks for all your help with getting my dialog to display correctly!

arnaiz
22nd February 2007, 19:31
Hi ToddAtWSU:

Why are you using 'mainWidget'?

As far as I can see, you are using a QWidget inside a QWidget. Your class ScreeningDialog is a QWidget, so yo can then omit:



QWidget *mainWidget = new QWidget( this );

and use 'this' insted of 'mainWidget'. For example:


.....
QGridLayout = new QGridLayout( this );
QLabel *outputDirLabel = new QLabel( tr( "Output Directory:" ), this );
mpOutputDirLnEd = new QLineEdit( this );
....


I think that may be your problem...

ToddAtWSU
22nd February 2007, 21:28
Thanks! That worked. I don't know why my way didn't work because on other dialogs I had created a mainWidget like I did here and it always worked fine. That is why I was so frustrated with this one, it was identical to how I set up other QDialogs but oh well...it worked with using "this" all the time. Thanks for your help!