Qt_GUI_BG_4_2 - 8BitsCoding/RobotMentor GitHub Wiki

Label Customize

// Label Custom
QFont label1Font("Times", 20, QFont::Bold);
QPalette label1Palette;
label1Palette.setColor(QPalette::Window, Qt::yellow);
label1Palette.setColor(QPalette::WindowText, Qt::blue);

QLabel * label1 = new QLabel(this);
label1->setAutoFillBackground(true);        // For Palette
label1->setText("My colored label");        // For Text
label1->setFont(label1Font);                // For Font
label1->setPalette(label1Palette);          // For Palette
label1->move(50, 50);

Button Customize

// Button Custom
#include <qpushbutton.h>

QFont buttonfont("Times", 20, QFont::Bold);
QPushButton* button = new QPushButton(this);
button->setText("Click Me");
button->setFont(buttonfont);
button->move(100, 250);
// .h
private slots:
    void buttonClicked();
// .cpp
connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));

// ...

void Widget::buttonClicked()
{
    QMessageBox::information(this, "Message", "You clicked on my button");
}

Window Size

private:
    QSize sizeHint() const;
QSize Widget::sizeHint() const
{
    return QSize(500, 500);
}