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. Saving margins of QTextEdit
Forum Updated to NodeBB v4.3 + New Features

Saving margins of QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtexteditpagesizemarginssave
10 Posts 2 Posters 2.9k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by mrjj
    #1

    Hello everyone,

    i want to save the pagemargins of QTextEdit in each Document without making a new one with this margin-information.

    Here's my code:

    void MainWindow::SeitenraenderOK() {
        dialog->close();
    
        if (rbutton7->isChecked())
        {
            w->setPageMargins(QMarginsF(25, 25, 25, 10));
        }
        else if(rbutton->isChecked())
        {
            w->setPageMargins(QMarginsF(15, 15, 15, 15));
        }
        else if(rbutton2->isChecked())
        {
            w->setPageMargins(QMarginsF(19.1, 25.4, 19.1, 25.4));
        }
        else if(rbutton3->isChecked())
        {
            w->setPageMargins(QMarginsF(50.8, 25.4, 50.8, 25.4));
        }
    }
    

    Here the PageMargins will be set, if the user check one radiobutton.

    And if the document is saved and the Margin for e.g. is this one:

      w->setPageMargins(QMarginsF(50.8, 25.4, 50.8, 25.4));
    

    and then reopen the document, the margin is this:

        w->setPageMargins(QMarginsF(25, 25, 25, 10));
    
    

    because when the application is initializing, this code executes...

    So, is there a possibility to save the Margin as part of the document?

    Thannks,
    HenrikSt

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

      Hi,

      Do you mean mean save it in the same file as the text data ? How are you doing it currently ?

      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
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Yes, you are right...

        I am actually saving the Document inside an .html File

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

          Then you could use a custom tag that you will parse in your application to contain that information.

          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
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            And how can i do that?

            Can give me a shrt example, please?

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

              Well, can you show how you are currently saving your document ?

              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
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7
                void PagesTextEdit::saveUnderDocument()
                {
                if (fileName.isEmpty()) {
                fileName = QFileDialog::getSaveFileName(this, tr("Speichern unter..."),
                QString("Unbenannt.htm"), tr("TextPad 1.0 (*.htm);;"));
                QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
                if(fileName.isEmpty())
                return;
                }
                
                QFile file(fileName, this);
                
                if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
                {
                   qDebug() << "Fehler beim Speichern der Datei";
                }
                
                QProgressDialog progress("Speichern - Fortschritt", "Abbrechen", 0, 10);
                progress.setWindowTitle("Speichern");
                progress.show();
                for(int i = 0; i < 10; i++) {
                    progress.setValue(i);
                    if(progress.wasCanceled())
                        break;
                    QTime saveTime = QTime::currentTime().addMSecs(40);
                    while(QTime::currentTime() < saveTime)
                        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
                }
                progress.setValue(1);
                
                
                QTextStream out(&file);
                out << encodeHtml( toHtml() );
                file.close();
                }
                
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Prepend a line which contains the information to what is returned by toHtml.

                  And when you load the file, remove that first line before setting the rest of the content on the QTextEdit and with the content of that line, update the margin.

                  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
                  1
                  • SGaistS SGaist

                    Prepend a line which contains the information to what is returned by toHtml.

                    And when you load the file, remove that first line before setting the rest of the content on the QTextEdit and with the content of that line, update the margin.

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    @SGaist Ok, and what can the line contains? I don't have any imaginations for that...

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

                      If you put your buttons in a QButtonGroup you could simply store the button id so you can programmatically check it when loading your document.

                      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

                      • Login

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