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

Question Concerning QWidget API

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 312 Views
  • 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.
  • F Offline
    F Offline
    FZGWWW
    wrote on last edited by
    #1

    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,10

    QThread* 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();
    }

    Christian EhrlicherC 1 Reply Last reply
    0
    • F FZGWWW

      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,10

      QThread* 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();
      }

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use layouts instead fixed-size stuff and please properly format your code so others can read it.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      F 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Use layouts instead fixed-size stuff and please properly format your code so others can read it.

        F Offline
        F Offline
        FZGWWW
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        Sorry ,I'm a new user of Qt Forum .Please forgive my untidy code(

        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