Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. i have a Qt code writed in C++ . i want translate it to python code

i have a Qt code writed in C++ . i want translate it to python code

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 3 Posters 1.2k 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.
  • B Offline
    B Offline
    Bouslama reda
    wrote on last edited by
    #1

    QTextDocument *doc = new QTextDocument;
    doc->setDocumentMargin(10);
    QTextCursor cursor(doc);

    cursor.movePosition(QTextCursor::Start);

    QTextTable *table = cursor.insertTable(properties.size() + 1, 2, tableFormat);
    QTextTableCell headerCell = table->cellAt(0, 0);
    QTextCursor headerCellCursor = headerCell.firstCursorPosition();
    headerCellCursor.insertText(QObject::tr("Name"), boldFormat);
    headerCell = table->cellAt(0, 1);
    headerCellCursor = headerCell.firstCursorPosition();
    headerCellCursor.insertText(QObject::tr("Value"), boldFormat);

    for(int i = 0; i < properties.size(); i++){
    QTextCharFormat cellFormat = i % 2 == 0 ? textFormat : alternateCellFormat;
    QTextTableCell cell = table->cellAt(i + 1, 0);
    cell.setFormat(cellFormat);
    QTextCursor cellCursor = cell.firstCursorPosition();
    cellCursor.insertText(properties.at(i)->name());

    cell = table->cellAt(i + 1, 1);
    cell.setFormat(cellFormat);
    cellCursor = cell.firstCursorPosition();
    cellCursor.insertText(properties.at(i)->value().toString() + " " + properties.at(i)->unit());
    

    }

    cursor.movePosition(QTextCursor::End);
    cursor.insertBlock();

    1 Reply Last reply
    0
    • DenniD Offline
      DenniD Offline
      Denni
      wrote on last edited by Denni
      #2

      Have you even tried rewriting this yourself in python / qt (of whatever style and flavor you plan on using which you did not state by the way) -- if no then frankly why should we?

      So as an assignment back to you -- we have your Qt? (5) C++ code please show us how you think it might be rendered in your Python version ?? and Qt (style and version ??) then perhaps we can help you refine that. Expecting us to do all your work is a bit presumptuous. Note in my experience most folks would just simply ignore this request while I am trying to actually help you understand what might be wrong with this request and help you build a better request that will get you a response

      madness... is like gravity, all takes is a little... push -- like from an unsolvable bug

      1 Reply Last reply
      1
      • B Offline
        B Offline
        Bouslama reda
        wrote on last edited by
        #3

        i need to export data from Qtablewidget to pdf version i found code writed in c++ and i want to translate it to python code !!?

        1 Reply Last reply
        0
        • DenniD Offline
          DenniD Offline
          Denni
          wrote on last edited by Denni
          #4

          Awesome sounds like an excellent endeavor keep in mind that python is a C based language and so is C++ granted their syntax is different but for the most part you should be able to analyze what you have in C++ and port that to python -- now sure you might run into a few issues and that is where we come in to help you with those specific issues not do all the work for you for free.

          So how do YOU think the C++ code should look if you rendered it in Python?

          Oh and I take it English (or Anglish ... American english) is not your native language as "writed" should be "written" instead no judgement just trying to help with that as well.

          So once you have some kind of python version of the above or a specific question about a specific piece (and do not just create a series of questions starting from the first line and going down - you will not learn if you do not try and I will almost guarantee you that this will not be your only walk down this path). Especially since all python Qt is ultimately based off of the C++ oriented Qt

          For instance that first line ought to be easy doc = QTextDocument() that is the python version of the C++ command as you are simply initializing the "doc" variable to the QTextDocument class object. Happy translating.

          madness... is like gravity, all takes is a little... push -- like from an unsolvable bug

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bouslama reda
            wrote on last edited by
            #5

            Merci pour votre conseil , le problème c'est que j'ai lu tout ce texte mais tellement sans bénéfice ,et le plus important pour moi en ce moment c'est avoir une réponse compatible avec la question, joueuse translation

            jsulmJ 1 Reply Last reply
            0
            • B Bouslama reda

              Merci pour votre conseil , le problème c'est que j'ai lu tout ce texte mais tellement sans bénéfice ,et le plus important pour moi en ce moment c'est avoir une réponse compatible avec la question, joueuse translation

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Bouslama-reda It is actually not hard to translate to Python. Qt is the same you just need to rewrite this code using Python syntax. So please try and tell us what is not working.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • DenniD Offline
                DenniD Offline
                Denni
                wrote on last edited by Denni
                #7

                I think his first issue of translation might be translating english (anglish) (what I said) to whatever is their native language but then again since I could not understand that last post they made I have no real clue as to what they said.

                madness... is like gravity, all takes is a little... push -- like from an unsolvable bug

                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