PDA

View Full Version : How to get qpushbutton to move down one row



seerofsorrow
16th November 2017, 22:16
<code>
#include "header2.h"
#include "ui_gui2.h"
#include <QPushButton>
#include <QSignalMapper>

Classy2::Classy2(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Classy2)
{
ui->setupUi(this);
}

Classy2::~Classy2()
{
delete ui;
}

//Actions for Templates

void Classy2::on_chronologyPushButton_pressed()
{
QFont font;
font.setPointSize(10);
font.setBold(true);

QLabel *numberLabel=new QLabel;
QTextEdit *chronoEdit=new QTextEdit;
QGridLayout *chronologyGridLayout=new QGridLayout;
QSignalMapper *signalMapper=new QSignalMapper(ui->chronologyWidget);


numberLabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Expanding);
numberLabel->setAlignment(Qt::AlignVCenter);
numberLabel->setFont(font);
numberLabel->setText("3.");

chronoEdit->setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Expanding);
chronoEdit->setAlignment(Qt::AlignVCenter);
chronoEdit->setFixedWidth(365);
chronoEdit->setFixedHeight(30);


ui->chronologyWidget->setMinimumSize(461,200);

connect(chronologyPushButton,SIGNAL(clicked()),sig nalMapper,SLOT(move()));
signalMapper->setMapping(chronologyPushButton,chronologyGridLayo ut);
chronologyGridLayout->addWidget(chronologyPushButton,4,0,Qt::AlignVCente r);






ui->chronologyGridLayout->addWidget(chronoEdit,2,1,Qt::AlignVCenter);
ui->chronologyGridLayout->addWidget(numberLabel,2,0,Qt::AlignVCenter);
ui->chronologyWidget->setLayout(ui->chronologyGridLayout);
ui->chronologyWidget->resize(401,91);
}
</code>

I have a qpushbutton inside of a qgridlayout inside of a qwidget. I am attempting to get the qpushbutton to move down one row once it's been clicked and a new label and qtextedit will be placed where the qpushbutton once was. however I ca't get the qpushbutton to move downwards. Can anybody tell me how to get the pushbutton tomove from 2,0 to 3,0 (or 4,0 from my code.) thank you

Ginsengelf
17th November 2017, 08:47
Hi, instead of moving the button it might be easier to hide it on click and to show another button in the row below.

Ginsengelf

high_flyer
17th November 2017, 08:58
<code>
should be:

[CODE]
then it will also work.

To your question:
you are creating a new grid layout every time the slot gets called, with this you are not changing anything (with respect to the button) in your original layout where the button is in which is interesting, since at the end of the slot you are using the original layout for the label and text edit...


void Classy2:n_chronologyPushButton_pressed()
{
QFont font;
font.setPointSize(10);
font.setBold(true);

QLabel *numberLabel=new QLabel;
QTextEdit *chronoEdit=new QTextEdit;
//QGridLayout *chronologyGridLayout=new QGridLayout;
QSignalMapper *signalMapper=new QSignalMapper(ui->chronologyWidget);


numberLabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy: :Expanding);
numberLabel->setAlignment(Qt::AlignVCenter);
numberLabel->setFont(font);
numberLabel->setText("3.");

chronoEdit->setSizePolicy(QSizePolicy::Expanding,QSizePolicy: :Expanding);
chronoEdit->setAlignment(Qt::AlignVCenter);
chronoEdit->setFixedWidth(365);
chronoEdit->setFixedHeight(30);


ui->chronologyWidget->setMinimumSize(461,200);

connect(chronologyPushButton,SIGNAL(clicked()),sig nalMapper,SLOT(move()));
signalMapper->setMapping(chronologyPushButton,chronologyGridLay out);
//chronologyGridLayout->addWidget(chronologyPushButton,4,0,Qt::AlignVCent er);


ui->chronologyGridLayout->addWidget(chronologyPushButton,4,0,Qt::AlignVCent er);

ui->chronologyGridLayout->addWidget(chronoEdit,2,1,Qt::AlignVCenter);
ui->chronologyGridLayout->addWidget(numberLabel,2,0,Qt::AlignVCenter);
ui->chronologyWidget->setLayout(ui->chronologyGridLayout);
ui->chronologyWidget->resize(401,91);
}


NOTE: I don't know if calling addWidget() for the button will do, or you may have to first take it out of the layout first - you need to try and see.