Question Concerning QWidget API
-
In the Widge I create a QWidget(named showImg) and get its API.When I resize it ,the QWidget(showImg) disappear?!Can anybody tell me why would this happen?/_
//In another Thread I use opencv to show a img constantly(using while(true)+waitKey()) in the Widget(in case this would be the source of problem)Here is the code:
#include "Visualphysic2.h"
#define sizeStandard 100,50
#define positionStandard 20,10QThread* useThread = new QThread;
runThread * runfunct = new runThread;
QTimer* timer;Visualphysic2::Visualphysic2(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
timer = new QTimer(this);setSize(); Connect(); runfunct->winID = (HWND)ui.showImg->winId(); runfunct->moveToThread(useThread); runfunct->Height =height(); runfunct->Width = width()*2/3; FILE* fp = freopen("data.txt", "r", stdin); QString iwS, iT, ipS; double wS, T, pS; cin >> wS >> T >> pS; iwS = QString::number(wS, 'f', 1); iT = QString::number(T, 'f', 1); ipS= QString::number(pS, 'f', 1); ui.wSEidt->setText(iwS); ui.timeEdit->setText(iT); ui.pSEdit->setText(ipS); freopen("CON", "r", stdin); cin.clear(); timer->start(100); useThread->start(); emit begin();
}
void Visualphysic2::createNewPert() {
QString iwS=ui.waveSpeed->text(),
iT=ui.timeEdit->text(),
ipS=ui.pSEdit->text();
double wS=iwS.toDouble(),
T=iT.toDouble(),
pS=ipS.toDouble();
FILE* fp = freopen("data.txt", "w", stdout);
printf("%lf\n%lf\n%lf", wS, T, pS);
fclose(fp);
emit getdata();
}
void Visualphysic2::updateSize() {
// runfunct->winID = (HWND)showImg->winId();
runfunct->Height = height()*1.5; runfunct->Width = width();
setSize();
// emit update();
}
void Visualphysic2::Connect() {
connect(this, SG(begin()), runfunct, SL(run()));
connect(this, SG(finish()), runfunct, SL(deleteLater));
connect(this, SG(finish()), useThread, SL(deleteLater));
connect(ui.pushButton, SG(clicked()), this, SL(createNewPert()));
connect(timer, SG(timeout()), this, SL(updateSize()));
connect(this, SG(getdata()), runfunct, SL(getdata()));
connect(this, SG(update()), runfunct, SL(redir()));
}void Visualphysic2::setSize() {
double Width = width(), Height = height();
double span = Height * 0.2;ui.waveSpeed->setGeometry(positionS**bolded text**tandard, sizeStandard); ui.wSEidt->setGeometry(100 + positionStandard, sizeStandard); ui.Time->setGeometry(positionStandard + span, sizeStandard); ui.timeEdit->setGeometry(100 + positionStandard + span, sizeStandard); ui.perticleSpeed->setGeometry(positionStandard + span * 2, sizeStandard); ui.pSEdit->setGeometry(100 + positionStandard + span * 2, sizeStandard); ui.pushButton->setGeometry(positionStandard + span * 4, 100, 50); //ui.showImg->move((1 / 3 * Width), 0 );
// ui.showImg->resize((2 / 3 * Width) * 10, Height * 10);(Once it is run ,the Widget disappear)
ui.showImg->show();
}
Visualphysic2::~Visualphysic2()
{
runfunct->flag = false;
emit finish();
} -
Use layouts instead fixed-size stuff and please properly format your code so others can read it.
-
@Christian-Ehrlicher
Sorry ,I'm a new user of Qt Forum .Please forgive my untidy code(