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. Display xml on qlabel
Forum Updated to NodeBB v4.3 + New Features

Display xml on qlabel

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.1k 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.
  • J Offline
    J Offline
    jss193
    wrote on last edited by
    #1

    Hello,

    Im trying to display coordinates file into a qlabel from xml file :

    $MOL
    
    
    
      6  6  0  0  0  0  0  0  0  0999 V2000
       -0.7145    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
       -0.7145   -0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
        0.0000   -0.8250    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
        0.7145   -0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
        0.7145    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
        0.0000    0.8250    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
      1  2  2  0        0
      2  3  1  0        0
      3  4  2  0        0
      4  5  1  0        0
      5  6  2  0        0
      6  1  1  0        0
    M  END
    
    

    From this I want to see a molecule, could someone give me an idea about how to do this from file into a qlabel??

    Thank you very much

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I don't want to nitpick but this is not XML at all.

      Do you mean, you want to draw some sort of molecule based on this content ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jss193
        wrote on last edited by
        #3

        Yes, thats exactly what I wish, to display it on a qlabel, is it possible??

        Thank you for your help

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You'll have to start by painting on a QPixmap first.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            Hi
            Here is a sample of drawing on pixmap and show in a label.

            int GetBarHeight(int MAX) {
              return rand() % (MAX-5)+5;
            }
            
            void MainWindow::on_pushButton_released() {
              int h = ui->label->height();
              int w = ui->label->width();
              QPixmap pix(w, h);
              QPainter paint(&pix);
              pix.fill( Qt::white );
              paint.setPen(QColor(0, 0, 0, 255));
              int y = 0;
              int x = 0;
              int bw = 10; // bar width
              for (int barcount = 0; barcount < 12; ++barcount) {
                paint.setBrush(QColor(255-x, 34+x, 255, 255));
                paint.drawRect(x, h - GetBarHeight(h),  bw, h );
                x += bw + 4;
              }
              paint.end();
              ui->label->setPixmap(pix);
            }
            
            

            alt text

            However, to draw a molecule, you have to read that format correctly. Is it your own format or
            something you found/got from another source?
            It sounds a bit like https://fileinfo.com/extension/mol
            which is used to describe something like
            alt text
            It comes in various version and contains heaps of information.
            What exactly do you want to draw ?

            1 Reply Last reply
            5
            • J Offline
              J Offline
              jss193
              wrote on last edited by
              #6

              Thats exactly what I want, but Im not sure about how to display it, creating a qpixmap object from that file?

              I want to paste the code and the program to display the molecule automatically.

              So grateful for your help

              mrjjM 1 Reply Last reply
              0
              • J jss193

                Thats exactly what I want, but Im not sure about how to display it, creating a qpixmap object from that file?

                I want to paste the code and the program to display the molecule automatically.

                So grateful for your help

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

                @jss193
                Hi
                Well first step is to understand the format
                alt text

                Have you worked with this before?

                1 Reply Last reply
                2
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  Just as update if someone finds this later.

                  Poster found a library http://openbabel.org/wiki/Main_Page
                  that can read this format and it turned out it can also export it as SVG image format.

                  QString smiles = ui->textEdit->toPlainText(); // this is input
                  string smi1 = smiles.toUtf8().constData();
                  OpenBabel::OBConversion conv;
                  conv.SetInAndOutFormats("smi","svg");
                  OpenBabel::OBMol mol;
                  conv.ReadString(&mol,smi1);
                  conv.WriteFile(&mol,"/path/jsfbn.svg");
                  

                  and we rendered it at the wanted size and displayed in a label.

                  void setSVG(QLabel *label, QString FileName, int width, int height)
                  {
                  QSvgRenderer render(FileName);
                  render.setViewBox(QRect(0, 0, width, height));
                  QPixmap pix(QSize(width, height));
                  pix.fill(Qt::white);
                  QPainter p(&pix);
                  render.render(&p, QRect(0, 0, width, height));
                  label->setPixmap(pix);
                  label->update();

                  }

                  void MainWindow::showEvent(QShowEvent *event)
                  {
                  setSVG(ui->label, "e:/Bi0.svg", ui->label->width(), ui->label->height());
                  }

                  Just asking QLabel to show it, would scale oddly. so we used QSvgRenderer directly.

                  1 Reply Last reply
                  1

                  • Login

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