Solved
-
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.
-
Try this:
@#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QtGui/QMainWindow>
namespace Ui
{
class MainWindow;
}
class QTimer;
class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
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));
}@ -
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..? -
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. -
ok sir,got it .thankyou again for your help.give me your mail address also please.
-
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. -
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..? -
sir i got the solution..it was @for(c=0;c<0;c=c+1)@
-
[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 ;) -
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
-
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_OBJECTpublic:
MainWindow(QWidget *parent = 0); ~MainWindow();
private:
Ui::MainWindow *ui;private slots:
private slots:
};
class mywidget : public QWidget // class mywidget
{
Q_OBJECTpublic:
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