2016-12-10 10 views
0

私はQT UIデザイナーを悩ませ、いくつかのボタンとスペーサーの周りに水平レイアウトボックスを追加しようとしています。しかし、私はいくつかの奇妙な結果を得ている:ボタンをレイアウトボックスに追加する際に、ボタンのスタイルを変更しないようにするにはどうすればよいですか?

はここに画像の前にあります:Spacer Plus Minus

そしてここでは、画像の後だ:Spacer Weird Minus Plus

はだけでなく、それは項目の順序を保持していない、それはまた、変更しましたこの奇妙な灰色のボックスにマイナスボタンのスタイル。

どうすればいいですか?または、ボタンのスタイルを制約に追加する前の状態に戻すにはどうすればよいですか?

+0

私はこれを再現することはできません。問題を示すqt-designer UIファイルを投稿してください。 – ekhumoro

答えて

0

enter image description here

私はQtのデザイナーにしようと、それが動作します。私は何かがあなたのボタンのスタイルを上書きすると思う。

また、ボタンスタイルをコード化しようとしましたか?このコードを使用するには、空のQWidgetウィンドウを作成し、2つのボタンを配置する必要があります。

main.cppに

#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; 
} 

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" 
#include <QApplication> 

int main(int argc, char *argv[]) 
{ 
    QApplication a(argc, argv); 
    Form mainWindow; 
    mainWindow.show(); 
    return a.exec(); 
} 
関連する問題