QT Knowledge Blog

QT Learning Progress:
Hello World
Window
Add Icon to Window
Window Type Classes

Widget:
Label
PushButton
LineEdit
HBox
VBox
GridLayout

Event handling:
Signals and Slots
RadioButtonExample
QCheckBox
QSpinBox
QLCDNumber Class
QLCD Random Number Generator
ComboBox
Slider
List WIdget
Font Combo Box
Table Widget
Calendar Widget

QInput Dialog
QColor Dialog
QFontDialog
QMessageBox

Single Signal with Multiple Slots
Single Slot with Multiple Signals

#include "widget.h"
#include<QVBoxLayout>
#include <QPushButton>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    resize(200,300);
    QVBoxLayout *vbox=new QVBoxLayout(this);

    lcd= new QLCDNumber();
    lcd->setStyleSheet("background-color:yellow");

    QPushButton *btn = new QPushButton();
    btn->setText("Random Generator");
    btn->setFont(QFont("Times", 14));
    btn->setStyleSheet("background-color:green");

    connect(btn, SIGNAL(clicked()),this, SLOT(randGenerator()));

    vbox->addWidget(lcd);
    vbox->addWidget(btn);

}

Widget::~Widget()
{
    lcd = new QLCDNumber;
}

void Widget::randGenerator()
{
    int randnumber = rand();
    lcd->display(randnumber);

}

QTComboBox

main.cpp

#include “widget.h”

#include<QApplication>

int main(int argc, char *argv[])

{

QApplication a(argc, argv);

Widget w;

w.show();

return a.exec();

}

widget.h
#ifdef WIDGET_H
#define WIDGET:H

#include<QWidget>
#include<QComboBox>

class Widget: public QWidget{

Q_OBject

public:
Widget(QWidget *parent = nullptr);
~Widget();
};

#endif //WIDGET_H

widget.cpp

#include “widget.h”
#include<QHBoxLayout>

Widget::Widget(QWidget *parent)
: QWidget(parent){

resize(100

}

Widget::~Widget(){

}

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *