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. Solved
Qt 6.11 is out! See what's new in the release blog

Solved

Scheduled Pinned Locked Moved General and Desktop
19 Posts 3 Posters 6.9k Views 1 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
    qxoz
    wrote on last edited by
    #7

    Because you have two loops one inside another.
    @for(r=0;r<1;r++) {
    for(c=0;c<1;c++) {
    QTableWidgetItem *item = new QTableWidgetItem();
    item->setText(textstr);
    ui->tableWidget->setItem(r,c,item);
    }
    }@

    Can you show what you expect at output? Then i can direct you to right way.

    ps - and please edit your firs post, add code tags.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sidharth
      wrote on last edited by
      #8

      i added tags and thanx for telling me.
      after your first reply i deleted my loops and right now i am not using any for loops.

      i exactly want like this
      i am drawing my desired output table.

       value
      
      1. 5
      2. 4
        3 3
        4 2
        5 1
        6 0

      like this i want to update my every new value in row1 and previous values will slide down.
      i am sending you my whole code
      .header
      @
      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H

      #include <QtGui/QMainWindow>

      namespace Ui
      {
      class MainWindow;
      }

      class MainWindow : public QMainWindow
      {
      Q_OBJECT

      public:
      void paintEvent(QPaintEvent *);

      MainWindow(QWidget *parent = 0);
      ~MainWindow();
      

      private:
      Ui::MainWindow *ui;
      private slots:
      void time();
      };

      #endif // MAINWINDOW_H
      @

      .cpp

      @
      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QGroupbox>
      #include <QPainter>
      #include <QPen>
      #include <QTimer>
      #include <QTime>
      int r=0;
      int c=0;
      int b=0;
      QString textstr;
      MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent), ui(new Ui::MainWindow)
      {
      ui->setupUi(this);

       QTimer *timer = new QTimer(this);
      
        timer->start(1000);
      
      
       connect(timer, SIGNAL(timeout()), this, SLOT(time()));
      

      }

      MainWindow::~MainWindow()
      {
      delete ui;
      }
      void MainWindow :: paintEvent(QPaintEvent *)
      {

      ui->tableWidget->insertRow(0);
      QTableWidgetItem* item = new QTableWidgetItem;
      item->setText(QString::number(b));
      ui->tableWidget->setItem(0, 0, item);

      item->setForeground(QColor::fromRgb(0,128,0));

      }

      void MainWindow :: time()
      {

      b++;

      update();

      }
      @

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sidharth
        wrote on last edited by
        #9

        mean to say like for row1 value5,then row 2 value 4 ..my column name is value..like this everytime my new value comes it will be in row 1 and previous will be sliding down the rows.

        you can check my code what i tried and please tell me the solution .you have already done 90% .just a small issue is coming that my every value is generating many times.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #10

          Try this:
          @#ifndef MAINWINDOW_H
          #define MAINWINDOW_H

          #include <QtGui/QMainWindow>

          namespace Ui
          {
          class MainWindow;
          }
          class QTimer;
          class MainWindow : public QMainWindow
          {
          Q_OBJECT

          public:
          MainWindow(QWidget *parent = 0);
          ~MainWindow();

          private:
          Ui::MainWindow *ui;
          int b;
          QTimer *timer
          private slots:
          void on_timeout();

          };

          #endif // MAINWINDOW_H@

          @#include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include <QTimer>

          MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent), ui(new Ui::MainWindow)
          {
          ui->setupUi(this);
          b = 0;
          timer = new QTimer(this);
          timer->start(1000);
          connect(timer, SIGNAL(timeout()), this, SLOT(on_timeout()));
          }

          MainWindow::~MainWindow()
          {
          delete ui;
          }

          void MainWindow :: on_timeout()
          {
          b++;
          ui->tableWidget->insertRow(0);
          QTableWidgetItem* item = new QTableWidgetItem;
          item->setText(QString::number(b));
          ui->tableWidget->setItem(0, 0, item);
          item->setForeground(QColor::fromRgb(0,128,0));
          }@

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sidharth
            wrote on last edited by
            #11

            thanx a lot sir for giving me your valuable time.you finally did it what i wanted.
            one more question i have to ask.
            can you tell me what was wrong with the previous code and what exactly insertrow(0); do..?

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qxoz
              wrote on last edited by
              #12

              Generally what i did, is remove paintEvent. As i wrote before "post":https://qt-project.org/forums/viewreply/128236/ and few other changes, you can see it by comparing code texts.
              About insert row you can read in "doc":http://qt-project.org/doc/qt-5.0/qtwidgets/qtablewidget.html it just adds an empty row into the table at given position, if there was a row, existing row moves down.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sidharth
                wrote on last edited by
                #13

                ok sir,got it .thankyou again for your help.give me your mail address also please.

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  qxoz
                  wrote on last edited by
                  #14

                  You're welcome.
                  Please mark thread as solved (edit first post and add to title [SOLVED] text).
                  You can send messages to mail address of members from this site. Just go to a members profile, there you will find send email link.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sidharth
                    wrote on last edited by
                    #15

                    sir please tell me that if i want to generate this data in all of my 4 columns then i am applying for loop
                    @for(c=0;c<4;c++)@ and then @setItem(0,c,item)@.
                    but its not working what is the problem i am facing..?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sidharth
                      wrote on last edited by
                      #16

                      sir i got the solution..it was @for(c=0;c<0;c=c+1)@

                      1 Reply Last reply
                      0
                      • raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #17

                        [quote author="sidharth" date="1370587123"]sir i got the solution..it was @for(c=0;c<0;c=c+1)@[/quote]
                        i doubt that the contents of this loop are ever executed ;)

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          sidharth
                          wrote on last edited by
                          #18

                          yes sir you are right... :)

                          can you help me further ?.now i have stuck in some other case.
                          i have pushbutton in forms created in base class mainwidow .now i have created one widget on the same form by drag and drop and again i created a pushbutton on the class widget.now i want that on the click of my pushbutton which was on the widget,my mainwindow button got disappeared...

                          how can it be possible.?please help me out

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            sidharth
                            wrote on last edited by
                            #19

                            i have promoted the widget to class mywidget and done some thing like this

                            .h
                            @#ifndef MAINWINDOW_H
                            #define MAINWINDOW_H

                            #include <QtGui/QMainWindow>

                            namespace Ui
                            {
                            class MainWindow;
                            }

                            class MainWindow : public QMainWindow //class mainwindow
                            {
                            Q_OBJECT

                            public:

                            MainWindow(QWidget *parent = 0);
                            ~MainWindow();
                            

                            private:
                            Ui::MainWindow *ui;

                            private slots:

                            private slots:

                            };

                            class mywidget : public QWidget // class mywidget

                            {
                            Q_OBJECT

                            public:

                            mywidget(QWidget *parent = 0);

                            public slots:

                            private:
                            Ui::MainWindow *ui;

                            private slots:
                            

                            void on_pushButton_2_clicked();
                            };
                            #endif // MAINWINDOW_H@

                            .cpp

                            @
                            #include "mainwindow.h"
                            #include "ui_mainwindow.h"

                            MainWindow::MainWindow(QWidget *parent)
                            : QMainWindow(parent), ui(new Ui::MainWindow)
                            {
                            ui->setupUi(this);

                            }

                            MainWindow::~MainWindow()
                            {
                            delete ui;
                            }
                            mywidget::mywidget(QWidget *parent)
                            : QWidget(parent)

                            {

                            }

                            void mywidget::on_pushButton_2_clicked()
                            {

                            }@

                            tell me how to do it sir ..
                            please

                            1 Reply Last reply
                            0

                            • Login

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