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. QTextEdit start text one tab in?
Forum Updated to NodeBB v4.3 + New Features

QTextEdit start text one tab in?

Scheduled Pinned Locked Moved Solved General and Desktop
qtextedit
16 Posts 5 Posters 3.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.
  • L Offline
    L Offline
    legitnameyo
    wrote on last edited by
    #7

    The text needs to be more to the left since I'll actually add a button ON the QTextEdit and it will be disastrous to have the button overlap the text, for obvious reasons. I am not yet sure about the whole "if you were to print then the viewport wont add those indent changes" thingy, but I would like to have the option to be able to print and have the format intact!

    tl;dr having a viewport margin would in my case be better than actually adding a tab into the document.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #8
      • Where do I append this "class" and "public" code? I've tried accessing setViewportMargin directly but the class is private. I can't -access through QTextEdit nor through QAbstractScrollArea. Again, where do I add it?

      Its a new class. a so called subclass. setViewportMargins can only be called by
      inheriting from QTextEdit.
      To use it:
      Add it to its own .h file. also add some #includes
      And that .h file to the project.
      then read
      http://doc.qt.io/qt-5/designer-using-custom-widgets.html
      To have be your text edit when run. ( if you use Designer)
      else you just have to new it your self.

      The promotion feature is very easy to use.
      if your new h file is called MyTextEdit.h
      then you just give TextEdit as classname and
      MyTextEdit.h for the file
      then when run, its your class instead.
      so its nto worse then right clicking your existing TextEdit,
      and select promote. then fill out info, press Add button, then promote button.

      L 1 Reply Last reply
      0
      • mrjjM mrjj
        • Where do I append this "class" and "public" code? I've tried accessing setViewportMargin directly but the class is private. I can't -access through QTextEdit nor through QAbstractScrollArea. Again, where do I add it?

        Its a new class. a so called subclass. setViewportMargins can only be called by
        inheriting from QTextEdit.
        To use it:
        Add it to its own .h file. also add some #includes
        And that .h file to the project.
        then read
        http://doc.qt.io/qt-5/designer-using-custom-widgets.html
        To have be your text edit when run. ( if you use Designer)
        else you just have to new it your self.

        The promotion feature is very easy to use.
        if your new h file is called MyTextEdit.h
        then you just give TextEdit as classname and
        MyTextEdit.h for the file
        then when run, its your class instead.
        so its nto worse then right clicking your existing TextEdit,
        and select promote. then fill out info, press Add button, then promote button.

        L Offline
        L Offline
        legitnameyo
        wrote on last edited by
        #9

        @mrjj I have not idea what you're talking about. I've tried adding a new .c and .h with a custom name and then "promoting" my QTextEdit to that same name, but that results in about 50 different errors regarding ui_myProject.h and other files. You continually wrote "Add it to its own .h file ..." what is "it"? Why do I need to add a .h file to the project, can't I just create one directly?

        jsulmJ 1 Reply Last reply
        0
        • L legitnameyo

          @mrjj I have not idea what you're talking about. I've tried adding a new .c and .h with a custom name and then "promoting" my QTextEdit to that same name, but that results in about 50 different errors regarding ui_myProject.h and other files. You continually wrote "Add it to its own .h file ..." what is "it"? Why do I need to add a .h file to the project, can't I just create one directly?

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

          @legitnameyo said in QTextEdit start text one tab in?:

          Why do I need to add a .h file to the project, can't I just create one directly?

          It's the same.
          If you have errors then show the errors and your code.

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

          1 Reply Last reply
          0
          • L Offline
            L Offline
            legitnameyo
            wrote on last edited by
            #11

            @mrjj said in QTextEdit start text one tab in?:

            Q_OBJECT

            #ifndef CUSTOMQTEXTEDIT_H
            #define CUSTOMQTEXTEDIT_H
            
            #include <QWidget>
            #include <QTextEdit>
            
            
            class customQTextEdit
            {
            public:
                customQTextEdit();
            
                customQTextEdit(QWidget *p = 0): customQTextEdit(p) {
                   setViewportMargins(30, 30, 30, 30); // add 30 pixels area around text
                   setStyleSheet("TextEdit { background: white; }"); // make the new "border" white
                }
            };
            
            #endif // CUSTOMQTEXTEDIT_H
            

            Gives me

            error: use of undeclared identifier 'setViewportMargins'
            error: use of undeclared identifier 'setStyleSheet'
            error: constructor for 'customQTextEdit' creates a delegation cycle
            
            mrjjM 1 Reply Last reply
            0
            • L legitnameyo

              @mrjj said in QTextEdit start text one tab in?:

              Q_OBJECT

              #ifndef CUSTOMQTEXTEDIT_H
              #define CUSTOMQTEXTEDIT_H
              
              #include <QWidget>
              #include <QTextEdit>
              
              
              class customQTextEdit
              {
              public:
                  customQTextEdit();
              
                  customQTextEdit(QWidget *p = 0): customQTextEdit(p) {
                     setViewportMargins(30, 30, 30, 30); // add 30 pixels area around text
                     setStyleSheet("TextEdit { background: white; }"); // make the new "border" white
                  }
              };
              
              #endif // CUSTOMQTEXTEDIT_H
              

              Gives me

              error: use of undeclared identifier 'setViewportMargins'
              error: use of undeclared identifier 'setStyleSheet'
              error: constructor for 'customQTextEdit' creates a delegation cycle
              
              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #12

              @legitnameyo
              you dont inherit QTextEdit.
              So that is why :)

              class customQTextEdit : public QTextEdit

              Also your constructor seems odd.
              make SURE you init base class.
              TextEdit(QWidget *p = 0): QTextEdit(p) ...

              1 Reply Last reply
              3
              • L Offline
                L Offline
                legitnameyo
                wrote on last edited by
                #13

                Now I get

                /error: out-of-line definition of 'customQTextEdit' does not match any declaration in 'customQTextEdit'
                

                for the code

                #ifndef CUSTOMQTEXTEDIT_H
                #define CUSTOMQTEXTEDIT_H
                
                #include <QWidget>
                #include <QTextEdit>
                
                
                class customQTextEdit: public QTextEdit
                {
                    customQTextEdit(QWidget *p = 0): QTextEdit(p) {
                            setViewportMargins(30, 30, 30, 30); // add 30 pixels area around text
                            setStyleSheet("TextEdit { background: white; }"); // make the new "border" white
                        }
                };
                
                
                #endif // CUSTOMQTEXTEDIT_H
                
                
                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  legitnameyo
                  wrote on last edited by
                  #14

                  Solved it by removing the function in the class of customQTextEdit and adding "public" right after the first {

                  mrjjM 1 Reply Last reply
                  0
                  • L legitnameyo

                    Solved it by removing the function in the class of customQTextEdit and adding "public" right after the first {

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

                    @legitnameyo
                    So finally it runs ?

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      legitnameyo
                      wrote on last edited by
                      #16

                      Yes, and works perfectly

                      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