Set to background Button on Label like C#
-
@ZekDe
Oh, so the flashing of buttons is done by hide/show hide/show ?
And it might be stopped in hide ?
Sounds like you should rather flash text on button so it cant be hidden.
It will be awful complicated if you use layouts as you cant have widgets on top of each other.
So i would find a better flashing method.@mrjj said in Set to background Button on Label like C#:
It will be awful complicated if you use layouts as you cant have widgets on top of each other.
One can't do it using the designer, true. But you can stack widgets on top of each other in a Gridlayout:
QGridLayout *gLayout = new QGridLayout(this); gLayout->addWidget(new QLabel("text below the Button",this),0,0); gLayout->addWidget(new QPushButton("Buttontext",this),0,0);
this actually should help the OP,
hasbecause hiding the button will not cause a resize of the layout, as the label is still in the cell and being drawn -
@mrjj said in Set to background Button on Label like C#:
It will be awful complicated if you use layouts as you cant have widgets on top of each other.
One can't do it using the designer, true. But you can stack widgets on top of each other in a Gridlayout:
QGridLayout *gLayout = new QGridLayout(this); gLayout->addWidget(new QLabel("text below the Button",this),0,0); gLayout->addWidget(new QPushButton("Buttontext",this),0,0);
this actually should help the OP,
hasbecause hiding the button will not cause a resize of the layout, as the label is still in the cell and being drawn -
@J.Hilk said in Set to background Button on Label like C#:
QGridLayout *gLayout = new QGridLayout(this);
gLayout->addWidget(new QLabel("text below the Button",this),0,0);
gLayout->addWidget(new QPushButton("Buttontext",this),0,0);Guys this is good solution but I am using ui , so that this is giving me a new object.Any better option?
-
@J.Hilk said in Set to background Button on Label like C#:
QGridLayout *gLayout = new QGridLayout(this);
gLayout->addWidget(new QLabel("text below the Button",this),0,0);
gLayout->addWidget(new QPushButton("Buttontext",this),0,0);Guys this is good solution but I am using ui , so that this is giving me a new object.Any better option?
@ZekDe
that should be easy enough, instead of creating a new QGridlayout, you reference the one you created in your UI-file (via Designer)//Assuming you placed already a QPushbutton in your Gridlayout via Designer QGridLayout *gLayout = ui->GridLayoutObjectName; gLayout->addWidget(new QLabel("text below the Button",this),0,0);
-
Hi
If they dont overlap, check that the button is in fact at 0,0
it works here
DESIGNER
CODE
QGridLayout *gLayout = ui->gridLayout;
gLayout->addWidget(new QLabel("text below the Button",this),0,0);
RESULT
-
Hi
If they still move a bit, its due to QLabel being other size that QButtonQGridLayout* gLayout = ui->gridLayout; QLabel *lab = new QLabel("text below the Button", this); lab->setSizePolicy( ui->pushButton->sizePolicy() ); // use fixed lab->setMinimumHeight(23); // same height gLayout->addWidget(lab, 0, 0); QTimer* tim = new QTimer(this); connect (tim, &QTimer::timeout, [this]() { (this->ui->pushButton->isVisible()) ? this->ui->pushButton->hide() : this->ui->pushButton->show(); }); tim->start(1000);
result:
-
ui->horizontalLayout->addWidget(ui->DKCS_btn1); ui->horizontalLayout->addWidget(new QLabel("text below the Button",this,0),0,0);