0

I'm messing around in the QT UI designer and trying to add a horizontal layout box around some buttons and a spacer. But I'm getting some weird results:

Here's the before image:Spacer Plus Minus

And here's the after image: Spacer Weird Minus Plus

Not only did it not retain the order of the items, it also changed the style of the minus button to this weird gray box.

How do I keep it from doing that? Or how do I change the button's style back to what it was before it was added to the constraint?

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Electric Coffee
  • 11,733
  • 9
  • 70
  • 131

1 Answers1

0

enter image description here

I tried in Qt designer and it works. I think something overwrites your button styles.

Also have you tried to code buttons style? To use this code you need to create empty QWidget window and place two buttons.

form.h

#ifndef FORM_H
#define FORM_H

#include <QWidget>
#include <QHBoxLayout>
#include <QMessageBox>

namespace Ui {
class Form;
}

class Form : public QWidget
{
    Q_OBJECT

public:
    explicit Form(QWidget *parent = 0);
    ~Form();

public slots:
    void plusClicked();
    void minusClicked();

private:
    Ui::Form *ui;
    QHBoxLayout *horizontalLayout;
};

#endif // FORM_H

form.h

#include "form.h"

Form::Form(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form)
{
    ui->setupUi(this);
    ui->pushButton->setText("+");
    ui->pushButton->setStyleSheet("background-color: white; border-style: solid; border-width: 1px; border-radius: 8px; border-color: gray; width: 60px; height: 30px; font-weight: bold; font-size: 14pt;");
    ui->pushButton_2->setText("-");
    ui->pushButton_2->setStyleSheet("background-color: white; border-style: solid; border-width: 1px; border-radius: 8px; border-color: gray; width: 60px; height: 30px; font-weight: bold; font-size: 14pt;");
    horizontalLayout = new QHBoxLayout(this);
    horizontalLayout->addStretch();
    horizontalLayout->addWidget(ui->pushButton);
    horizontalLayout->addWidget(ui->pushButton_2);
    this->setLayout(horizontalLayout);
    connect(ui->pushButton, &QPushButton::clicked, this, &Form::plusClicked);
    connect(ui->pushButton_2, &QPushButton::clicked, this, &Form::minusClicked);
}

void Form::plusClicked()
{
    QMessageBox::information(this, "Form", "Plus button clicked!", QMessageBox::Ok);
}

void Form::minusClicked()
{
    QMessageBox::information(this, "Form", "Minus button clicked!", QMessageBox::Ok);
}

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

main.cpp

#include "form.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Form mainWindow;
    mainWindow.show();
    return a.exec();
}
Cobra91151
  • 610
  • 4
  • 14