Hello Developers,
I have been trying to set an icon for a tab in a tabWidget using code but failed so far. Its easier with the form designer but I need to use code to make my app dynamic.
Here’s the code for mainwindow.cpp, the rest of the files are the default for a MainWindow project.
Please show me how to set icons with size 20×20p for both tab1 and tab2 below.
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTabWidget *tabWidget = new QTabWidget;
QWidget *tab1 = new QWidget;
QWidget *tab2 = new QWidget;
setCentralWidget(tabWidget);
tabWidget->insertTab(0, tab1, "Tab 1");
tabWidget->insertTab(1, tab2, "Tab 2");
}
MainWindow::~MainWindow()
{
delete ui;
}
Thanks in advance
↧