Заголовки:
Код: Выделить всё
#ifndef TOPAREACLASS_H
#define TOPAREACLASS_H
#include
#include
#include
#include
#include
#include
#include
#include
class topAreaClass : public QWidget
{
Q_OBJECT
public:
explicit topAreaClass(const QString& label,const QString& path, QWidget *parent = nullptr);
private:
QWidget* topArea;
QWidget* leftTopArea;
QHBoxLayout* topHBoxLayout;
QVBoxLayout* leftTopVBoxLayout;
QPixmap* m_pixLabelCurrency;
QLabel* m_currencyLabelPicture;
QLabel* m_nameOfCurrency;
QLineEdit* m_edit1;
};
#endif // TOPAREACLASS_H
Код: Выделить всё
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
#include
#include
#include
#include
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private slots:
private:
QWidget* topArea;
QWidget* leftTopArea;
QHBoxLayout* topHBoxLayout;
QVBoxLayout* leftTopVBoxLayout;
QPixmap* m_pixLabelCurrency;
QLabel* m_currencyLabelPicture;
QLabel* m_nameOfCurrency;
QLineEdit* m_edit1;
};
#endif // WIDGET_H
Код: Выделить всё
#include "widget.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
Код: Выделить всё
#include "topareaclass.h"
topAreaClass::topAreaClass(const QString& Label,const QString& path, QWidget *parent)
: QWidget{parent}
{
//topArea
topArea = new QWidget(this);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setFixedSize(500, 70);
setStyleSheet("background: grey;");
//leftTopArea
leftTopArea = new QWidget(topArea);
leftTopArea->setFixedSize(70, 70);
leftTopArea->setStyleSheet("background: grey;");
leftTopVBoxLayout = new QVBoxLayout(leftTopArea);
leftTopVBoxLayout->setContentsMargins(5,5,5,5);
//Flag
m_pixLabelCurrency = new QPixmap(path);
m_currencyLabelPicture = new QLabel();
m_currencyLabelPicture->setPixmap(m_pixLabelCurrency->scaled(60,30, Qt::KeepAspectRatio));
m_currencyLabelPicture->setAlignment(Qt::AlignCenter);
//Usd
m_nameOfCurrency = new QLabel(Label);
m_nameOfCurrency->setAlignment(Qt::AlignCenter);
leftTopVBoxLayout->addWidget(m_currencyLabelPicture);
leftTopVBoxLayout->addWidget(m_nameOfCurrency);
//edit1 (topRight)
m_edit1 = new QLineEdit("100000");
m_edit1->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
m_edit1->setStyleSheet("border: none;"
"font-size: 35px;"
"margin-right: 10px;");
m_edit1->setFixedHeight(70);
//QHBoxLayout
topHBoxLayout = new QHBoxLayout(this);
topHBoxLayout->setContentsMargins(0,0,0,0);
topHBoxLayout->addWidget(leftTopArea);
topHBoxLayout->addStretch();
topHBoxLayout->addWidget(m_edit1);
}
Код: Выделить всё
#include "widget.h"
#include "topareaclass.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
setFixedSize(500,700);
setStyleSheet("background: black;");
setWindowTitle("Currency Convertor");
QVBoxLayout* mainLayout = new QVBoxLayout(this);
topAreaClass* top1 = new topAreaClass("USD", ":/new/prefix1/build/usa.png");
topAreaClass* top2 = new topAreaClass("UAH", ":/new/prefix1/build/uah.png");
mainLayout->addWidget(top1);
mainLayout->addWidget(top2);
mainLayout->addStretch();
}
Widget::~Widget() {}

Как это исправить, чтобы вокруг виджетов не оставалось места?
Подробнее здесь: https://stackoverflow.com/questions/786 ... -my-widget