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 to get one common cell in QTableWidget
Forum Updated to NodeBB v4.3 + New Features

how to get one common cell in QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 7 Posters 1.8k Views 2 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #3

    I delete here and post in the orginal . . Could you please answer my question

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Qt Enthusiast
      wrote on last edited by Qt Enthusiast
      #4

      I have written a code

      #include "mainwindow.h"
      #include <QTableWidget>

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent)
      {
      QTableWidget * t = new QTableWidget;
      t->setColumnCount(5);
      t->setRowCount(2);
      QStringList headerLabels;

      QString col1 = "Col1";
      QString col2 = "Col2";
      
      QString col3 = "Col3";
      
      QString col4 = "Col4";
      
      QString col5 = "Col5";
      
      headerLabels << col1 << col2 << col3 << col4 << col5;
      t->setHorizontalHeaderLabels(headerLabels);
      t->show();
      

      }

      I am getting following table 0_1544270808170_Table1.png

      I do not want the cell in red and in fact I need 1 in place of red cell any idea

      mrjjM 1 Reply Last reply
      0
      • Q Qt Enthusiast

        I have written a code

        #include "mainwindow.h"
        #include <QTableWidget>

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent)
        {
        QTableWidget * t = new QTableWidget;
        t->setColumnCount(5);
        t->setRowCount(2);
        QStringList headerLabels;

        QString col1 = "Col1";
        QString col2 = "Col2";
        
        QString col3 = "Col3";
        
        QString col4 = "Col4";
        
        QString col5 = "Col5";
        
        headerLabels << col1 << col2 << col3 << col4 << col5;
        t->setHorizontalHeaderLabels(headerLabels);
        t->show();
        

        }

        I am getting following table 0_1544270808170_Table1.png

        I do not want the cell in red and in fact I need 1 in place of red cell any idea

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #5

        @Qt-Enthusiast
        Hi
        You can look on how to style the red part
        http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtableview
        (QTableView QTableCornerButton::section)

        I dont get this part

        • and in fact I need 1 in place of red cell

        Can you explain better ?

        you mean dont have any headerLabels so
        first row start there ?

        1 Reply Last reply
        1
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #6

          yes
          The row should start from red cell and Also I want the form as

          0_1544279981038_Sample.png

          mrjjM 1 Reply Last reply
          0
          • Q Qt Enthusiast

            yes
            The row should start from red cell and Also I want the form as

            0_1544279981038_Sample.png

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #7

            @Qt-Enthusiast
            hi
            you can hide the header with
            ui->tableWidget->verticalHeader()->setVisible(false);

            1 Reply Last reply
            2
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #8

              What I have understood now is that you don't want vertical headers. Can you just try the following in your constructor ?

              t->verticalHeader()->hide();

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              2
              • Q Offline
                Q Offline
                Qt Enthusiast
                wrote on last edited by
                #9

                HOW TO INSERT Label + button at the last cells of last co![0_1544280441906_

                0_1544280521223_s1.png

                aha_1980A 1 Reply Last reply
                0
                • Q Qt Enthusiast

                  HOW TO INSERT Label + button at the last cells of last co![0_1544280441906_

                  0_1544280521223_s1.png

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  @Qt-Enthusiast

                  http://doc.qt.io/qt-5/qtablewidget.html#setCellWidget

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  -1
                  • Q Offline
                    Q Offline
                    Qt Enthusiast
                    wrote on last edited by
                    #11

                    In this case I have a Label + button . I can I get both . Do I have to put a custom class

                    aha_1980A 1 Reply Last reply
                    0
                    • Q Qt Enthusiast

                      In this case I have a Label + button . I can I get both . Do I have to put a custom class

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @Qt-Enthusiast said in how to get one common cell in QTabelWidget:

                      In this case I have a Label + button . I can I get both . Do I have to put a custom class

                      Either that (a QHBoxLayout for example) or just put them in two columns

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      0
                      • Q Offline
                        Q Offline
                        Qt Enthusiast
                        wrote on last edited by
                        #13

                        @Qt-Enthusiast said in how to get one common cell in QTableWidget:

                        #include "mainwindow.h"
                        #include <QTableWidget>
                        MainWindow::MainWindow(QWidget *parent) :
                        QMainWindow(parent)
                        {
                        QTableWidget * t = new QTableWidget;
                        t->setColumnCount(5);
                        t->setRowCount(2);
                        QStringList headerLabels;
                        QString col1 = "Col1";
                        QString col2 = "Col2";

                        QString col3 = "Col3";

                        QString col4 = "Col4";

                        QString col5 = "Col5";

                        headerLabels << col1 << col2 << col3 << col4 << col5;
                        t->setHorizontalHeaderLabels(headerLabels);
                        t->show();

                        }

                        getting compilation error her

                        #include "mainwindow.h"
                        #include <QTableWidget>
                        #include <QPushButton>
                        #include <QComboBox>
                        #include <QLineEdit>
                        #include <QHBoxLayout>
                        #include <QLabel>
                        #include <QHBoxLayout>

                        MainWindow::MainWindow(QWidget *parent) :
                        QMainWindow(parent)
                        {
                        QTableWidget * t = new QTableWidget;
                        t->setColumnCount(5);
                        t->setRowCount(3);
                        QStringList headerLabels;

                        QString col1 = "Col1";
                        QString col2 = "Col2";

                        QString col3 = "Col3";

                        QString col4 = "Col4";

                        QString col5 = "Col5";

                        headerLabels << col1 << col2 << col3 << col4 << col5;
                        t->setHorizontalHeaderLabels(headerLabels);
                        QPushButton* button = new QPushButton();
                        button->setText("No of Mappings");

                        QPushButton* button1 = new QPushButton();
                        button1->setText("Group");

                        QPushButton* button2 = new QPushButton();
                        button2->setText("Type");

                        QPushButton* button3 = new QPushButton();
                        button3->setText("Rules");

                        QPushButton* button4 = new QPushButton();
                        button4->setText("Options");

                        t->setCellWidget(0,0,button);
                        t->setCellWidget(0,1,button1);
                        t->setCellWidget(0,2,button2);
                        t->setCellWidget(0,3,button3);
                        t->setCellWidget(0,4,button4);

                        t->setCellWidget(1,2,new QComboBox());
                        t->setCellWidget(2,2,new QComboBox());
                        t->setCellWidget(1,3,new QLineEdit());
                        t->setCellWidget(2,3,new QLineEdit());
                        QHBoxLayout* hbox = new QHBoxLayout ;

                        QLabel* label = new QLabel("Options");
                        QPushButton * button22;
                        button2->setText("+");
                        hbox->addWidget(label);
                        hbox->addWidget(button22);
                        t->setCellWidget(1,4,hbox);

                        QHBoxLayout* hbox1 = new QHBoxLayout ;
                        QPushButton * button31 = new QPushButton;
                        button31->setText("+");
                        hbox1->addWidget(label);
                        hbox1->addWidget(button3);
                        t->setCellWidget(1,4,hbox1);

                        t->show();

                        }

                        MainWindow::~MainWindow()
                        {

                        }

                        jsulmJ 1 Reply Last reply
                        0
                        • Q Qt Enthusiast

                          @Qt-Enthusiast said in how to get one common cell in QTableWidget:

                          #include "mainwindow.h"
                          #include <QTableWidget>
                          MainWindow::MainWindow(QWidget *parent) :
                          QMainWindow(parent)
                          {
                          QTableWidget * t = new QTableWidget;
                          t->setColumnCount(5);
                          t->setRowCount(2);
                          QStringList headerLabels;
                          QString col1 = "Col1";
                          QString col2 = "Col2";

                          QString col3 = "Col3";

                          QString col4 = "Col4";

                          QString col5 = "Col5";

                          headerLabels << col1 << col2 << col3 << col4 << col5;
                          t->setHorizontalHeaderLabels(headerLabels);
                          t->show();

                          }

                          getting compilation error her

                          #include "mainwindow.h"
                          #include <QTableWidget>
                          #include <QPushButton>
                          #include <QComboBox>
                          #include <QLineEdit>
                          #include <QHBoxLayout>
                          #include <QLabel>
                          #include <QHBoxLayout>

                          MainWindow::MainWindow(QWidget *parent) :
                          QMainWindow(parent)
                          {
                          QTableWidget * t = new QTableWidget;
                          t->setColumnCount(5);
                          t->setRowCount(3);
                          QStringList headerLabels;

                          QString col1 = "Col1";
                          QString col2 = "Col2";

                          QString col3 = "Col3";

                          QString col4 = "Col4";

                          QString col5 = "Col5";

                          headerLabels << col1 << col2 << col3 << col4 << col5;
                          t->setHorizontalHeaderLabels(headerLabels);
                          QPushButton* button = new QPushButton();
                          button->setText("No of Mappings");

                          QPushButton* button1 = new QPushButton();
                          button1->setText("Group");

                          QPushButton* button2 = new QPushButton();
                          button2->setText("Type");

                          QPushButton* button3 = new QPushButton();
                          button3->setText("Rules");

                          QPushButton* button4 = new QPushButton();
                          button4->setText("Options");

                          t->setCellWidget(0,0,button);
                          t->setCellWidget(0,1,button1);
                          t->setCellWidget(0,2,button2);
                          t->setCellWidget(0,3,button3);
                          t->setCellWidget(0,4,button4);

                          t->setCellWidget(1,2,new QComboBox());
                          t->setCellWidget(2,2,new QComboBox());
                          t->setCellWidget(1,3,new QLineEdit());
                          t->setCellWidget(2,3,new QLineEdit());
                          QHBoxLayout* hbox = new QHBoxLayout ;

                          QLabel* label = new QLabel("Options");
                          QPushButton * button22;
                          button2->setText("+");
                          hbox->addWidget(label);
                          hbox->addWidget(button22);
                          t->setCellWidget(1,4,hbox);

                          QHBoxLayout* hbox1 = new QHBoxLayout ;
                          QPushButton * button31 = new QPushButton;
                          button31->setText("+");
                          hbox1->addWidget(label);
                          hbox1->addWidget(button3);
                          t->setCellWidget(1,4,hbox1);

                          t->show();

                          }

                          MainWindow::~MainWindow()
                          {

                          }

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          @Qt-Enthusiast said in how to get one common cell in QTableWidget:

                          getting compilation error her

                          Don't you think you should post the error?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • VRoninV Offline
                            VRoninV Offline
                            VRonin
                            wrote on last edited by
                            #15

                            The ideal solution is using a custom QStyledItemDelegate. If you can't be asked/want to delay the painful process you can design your label+button as a widget in designer and then use this delegate

                            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                            ~Napoleon Bonaparte

                            On a crusade to banish setIndexWidget() from the holy land of Qt

                            1 Reply Last reply
                            4

                            • Login

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