Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I add Imaged on the Tab ?
Qt 6.11 is out! See what's new in the release blog

How do I add Imaged on the Tab ?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 3.8k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Smaranil
    wrote on last edited by
    #1

    This is what i have now
    alt text

    This is what i want it to be
    alt text

    Instead of those Text i want to add those Images on the Tab

    Please ignore the Borders since i want a cleaner look .

    K 1 Reply Last reply
    0
    • S Smaranil

      This is what i have now
      alt text

      This is what i want it to be
      alt text

      Instead of those Text i want to add those Images on the Tab

      Please ignore the Borders since i want a cleaner look .

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Smaranil

      Did you see already this version of addTab?

      Vote the answer(s) that helped you to solve your issue(s)

      S 1 Reply Last reply
      0
      • S Offline
        S Offline
        Smaranil
        wrote on last edited by
        #3

        i am unable to understand that if there is any video explaining this it would be helpful. since i am not a Coder i only do Designing and a little bit of Copy paste work

        K Taz742T 2 Replies Last reply
        0
        • S Smaranil

          i am unable to understand that if there is any video explaining this it would be helpful. since i am not a Coder i only do Designing and a little bit of Copy paste work

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Smaranil

          How and with what did you create the tabs shown above?

          Probably best is to post a code section.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          1
          • S Smaranil

            i am unable to understand that if there is any video explaining this it would be helpful. since i am not a Coder i only do Designing and a little bit of Copy paste work

            Taz742T Offline
            Taz742T Offline
            Taz742
            wrote on last edited by Taz742
            #5

            @Smaranil
            if you are designer You do not need to know this.
            And if you want to know how to do this, then you should learn how to do it.

            Do what you want.

            1 Reply Last reply
            0
            • K koahnig

              @Smaranil

              Did you see already this version of addTab?

              S Offline
              S Offline
              Smaranil
              wrote on last edited by koahnig
              #6

              @koahnig I used QTabWidegt and used Stylesheet to make it look that way . Still since u asked for the whole code i will give it

              Header Files

              mainwindow.h

              #ifndef MAINWINDOW_H
              #define MAINWINDOW_H
              
              #include <QMainWindow>
              #include <QMouseEvent>
              
              
              namespace Ui {
              class MainWindow;
              }
              
              class MainWindow : public QMainWindow
              {
                  Q_OBJECT
              
              public:
                  explicit MainWindow(QWidget *parent = 0);
                  ~MainWindow();
              
              
              private:
                  Ui::MainWindow *ui;
                  void mousePressEvent(QMouseEvent *event);
                  void mouseMoveEvent(QMouseEvent *event);
                  int m_nMouseClick_X_Coordinate;
                  int m_nMouseClick_Y_Coordinate;
              
              
              };
              
              #endif // MAINWINDOW_H
              
              

              main.cpp

              #include "mainwindow.h"
              #include <QApplication>
              
              int main(int argc, char *argv[])
              {
                  QApplication a(argc, argv);
                  MainWindow w;
              
              
                  w.show();
              
              
              
                  return a.exec();
              }
              

              mainwindow.cpp

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              
              MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent,Qt::FramelessWindowHint),
                  ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
              }
              
              MainWindow::~MainWindow()
              {
                  delete ui;
              }
              
              void MainWindow::mousePressEvent(QMouseEvent *event) {
                  m_nMouseClick_X_Coordinate = event->x();
                  m_nMouseClick_Y_Coordinate = event->y();
              }
              
              void MainWindow::mouseMoveEvent(QMouseEvent *event) {
                  move(event->globalX()-m_nMouseClick_X_Coordinate,event->globalY()-m_nMouseClick_Y_Coordinate);
              }
              

              stylesheet of Qtabwidget

              QTabBar::tab:selected { 
              color: rgb(0, 0, 0);
              background-color:rgb(255, 255, 255);
              }
              
              QTabBar::tab:!selected {
              color:rgb(0, 0, 0);
              background-color:rgb(223, 223, 223);
              border-bottom-color: #4FA600;
              }
              
              QTabWidget:pane { /*replace icon text as pane ok....*/
              margin: 1px,1px,1px,1px;
              background-color: rgb(255,255,255);
              }
              
              QTabBar::tab { 
              
              height: 130px;
              width: 130px;
              background-color: rgb(255,255,255);
              } 
              
              QTabWidget{
              background-color: rgb(255,255,255);
              font: 75 14pt "Arial Rounded MT Bold";
              }
              
              QTabWidget::tab-bar { 
              left: 5px; /* move to the right by 5px */
              bottom: -1px;
              background-color: rgb(255,255,255); } 
              
              QTabWidget::pane { border: 0; }
              
              

              [edit:koahnig revised the code tagged sections for easier reading]

              K 1 Reply Last reply
              0
              • S Smaranil

                @koahnig I used QTabWidegt and used Stylesheet to make it look that way . Still since u asked for the whole code i will give it

                Header Files

                mainwindow.h

                #ifndef MAINWINDOW_H
                #define MAINWINDOW_H
                
                #include <QMainWindow>
                #include <QMouseEvent>
                
                
                namespace Ui {
                class MainWindow;
                }
                
                class MainWindow : public QMainWindow
                {
                    Q_OBJECT
                
                public:
                    explicit MainWindow(QWidget *parent = 0);
                    ~MainWindow();
                
                
                private:
                    Ui::MainWindow *ui;
                    void mousePressEvent(QMouseEvent *event);
                    void mouseMoveEvent(QMouseEvent *event);
                    int m_nMouseClick_X_Coordinate;
                    int m_nMouseClick_Y_Coordinate;
                
                
                };
                
                #endif // MAINWINDOW_H
                
                

                main.cpp

                #include "mainwindow.h"
                #include <QApplication>
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                    MainWindow w;
                
                
                    w.show();
                
                
                
                    return a.exec();
                }
                

                mainwindow.cpp

                #include "mainwindow.h"
                #include "ui_mainwindow.h"
                
                MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent,Qt::FramelessWindowHint),
                    ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                }
                
                MainWindow::~MainWindow()
                {
                    delete ui;
                }
                
                void MainWindow::mousePressEvent(QMouseEvent *event) {
                    m_nMouseClick_X_Coordinate = event->x();
                    m_nMouseClick_Y_Coordinate = event->y();
                }
                
                void MainWindow::mouseMoveEvent(QMouseEvent *event) {
                    move(event->globalX()-m_nMouseClick_X_Coordinate,event->globalY()-m_nMouseClick_Y_Coordinate);
                }
                

                stylesheet of Qtabwidget

                QTabBar::tab:selected { 
                color: rgb(0, 0, 0);
                background-color:rgb(255, 255, 255);
                }
                
                QTabBar::tab:!selected {
                color:rgb(0, 0, 0);
                background-color:rgb(223, 223, 223);
                border-bottom-color: #4FA600;
                }
                
                QTabWidget:pane { /*replace icon text as pane ok....*/
                margin: 1px,1px,1px,1px;
                background-color: rgb(255,255,255);
                }
                
                QTabBar::tab { 
                
                height: 130px;
                width: 130px;
                background-color: rgb(255,255,255);
                } 
                
                QTabWidget{
                background-color: rgb(255,255,255);
                font: 75 14pt "Arial Rounded MT Bold";
                }
                
                QTabWidget::tab-bar { 
                left: 5px; /* move to the right by 5px */
                bottom: -1px;
                background-color: rgb(255,255,255); } 
                
                QTabWidget::pane { border: 0; }
                
                

                [edit:koahnig revised the code tagged sections for easier reading]

                K Offline
                K Offline
                koahnig
                wrote on last edited by
                #7

                @Smaranil

                if you got to this page, there are apparently examples of including icons.

                However, I would not know how you can select and modify a specific tab there using the style-sheet.

                However, you can also source code to set an icon

                you would need something like

                QIcon myIcon ("c:/icons/myIconFile");
                ui->%here is the name of the tab widget%->setTabIcon ( 0, myIcon );
                

                QIcon contructor tells you about the read options.

                Vote the answer(s) that helped you to solve your issue(s)

                1 Reply Last reply
                1
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  You can assign icons directly in Designer
                  alt text

                  Note, that if the app should be anything more that a demo, you should use
                  a QResource file to hold the images and not be tempted to use "Choose file" and point to image
                  on random paths.

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved