PDA

View Full Version : Where is my QPushButtons



HelloDan
30th March 2009, 05:34
Test::Test(QWidget* parent):QDialog(parent)
{
setBackgroundRole(QPalette::Dark);
setAutoFillBackground(true);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

//buttons settings
settingButton=new QPushButton;
settingButton->setText("settings");
settingButton->adjustSize();
oneStepButton=new QPushButton;
oneStepButton->setText("one step");
oneStepButton->adjustSize();
runAllButton=new QPushButton;
runAllButton->setText("run all");
runAllButton->adjustSize();
//place the buttons in a proper position
settingButton->move(5, 5);
oneStepButton->move(5 + settingButton->width() + 5, 5);
runAllButton->move(15+settingButton->width()+oneStepButton->width(),5);

//plotter settings
minX = 0.0;
maxX = 10.0;
numXTicks = 5;

minY = 0.0;
maxY = 10.0;
numYTicks = 5;

iniPoints();
resize(600,400);
}

void Test::refreshPixmap()
{
pixmap = QPixmap(size());
pixmap.fill(this, 0, 0);

QPainter painter(&pixmap);
painter.initFrom(this);
drawGrid(&painter);
drawPoints(&painter);
update();
}




In this program, I want to draw a coordinate and points in it. above the coordinate, I post three QPushButtons . Now my app can be executed, but the buttons can not turn up, leaving only the coordinate. I don't know why? Do you have any advise?

Thanks!

HelloDan
30th March 2009, 06:27
settingButton->show();
oneStepButton->show();
runAllButton->show();


I add these three lines in the constructor function. but the button post in the leftup corner, not in the dialog.

talk2amulya
30th March 2009, 06:31
make the dialog as the parent of the buttons

spirit
30th March 2009, 06:40
maybe it would be better to use one of the layouts classes to manage controls position insted of using?


...
settingButton->move(5, 5);
oneStepButton->move(5 + settingButton->width() + 5, 5);
runAllButton->move(15+settingButton->width()+oneStepButton->width(),5);
...

:)

HelloDan
30th March 2009, 07:15
settingButton=new QPushButton(this);

it works!

thanks