Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. expanding QPlainTextEdit boxes in QTabWidgets
QtWS25 Last Chance

expanding QPlainTextEdit boxes in QTabWidgets

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
designerqtabwidgetqplaintextedit
10 Posts 2 Posters 1.9k 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 24 Jun 2019, 15:49 last edited by
    #1

    Hi all -

    I'm starting to clean up the UI of an app I've been using for awhile. Part of my goal is to eliminate as many magic numbers as possible within the code for the UI.

    I have a QTabWidget with 4 tabs:
    0_1561391282440_tabs.png
    I'd like the QPlainTextEdit objects to fill the available space, but I can't figure out how. Setting their properties to expanding doesn't do it. Can someone tell me what I'm missing?

    Thanks...

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Jun 2019, 18:29 last edited by
      #2

      Hi,

      Why not make the QPlainTextEdit directly the content of the tab ?

      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
      • M Offline
        M Offline
        mzimmers
        wrote on 24 Jun 2019, 18:33 last edited by
        #3

        Hi SGaist -

        From the docs:

        The normal way to use QTabWidget is to do the following:
        
        Create a QTabWidget.
        Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
        Insert child widgets into the page widget, using layouts to position them as normal.
        Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.
        

        I understood this to mean I had to do it the way I described above. Am I misinterpreting that?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 24 Jun 2019, 19:56 last edited by
          #4

          That's valid and written so because most of the time, you'll have complex widgets there. Since you are using only one widget, there's nothing wrong at adding it directly to the QTabWidget.

          AFAICT, in your example, you are not using layouts, that's one thing you should do.

          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
          • M Offline
            M Offline
            mzimmers
            wrote on 24 Jun 2019, 20:21 last edited by
            #5

            OK, I don't know how to do this, at least not in Designer. Are you suggesting that I have a QTabWidget, and add 4 QPlainTextEdits to it? I can't seem to avoid getting that intermediate (layout) QWidget inserted, nor do I see how to delete them.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 24 Jun 2019, 20:25 last edited by SGaist
              #6

              I don't know either, I usually use Qt directly when dealing with that kind of stuff.

              [edit: reworded to be clearer SGaist]

              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
              • M Offline
                M Offline
                mzimmers
                wrote on 25 Jun 2019, 22:38 last edited by
                #7

                So...

                1. create the QTabWidget
                2. create the pages (as QPlainTextEdit objects?) as necessary
                3. setSizePolicy on the pages to expanding, expanding
                  4 call addTab() for each page

                Is that about right?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 26 Jun 2019, 17:58 last edited by
                  #8

                  That's the thing, you shouldn't need to do anything special. If you call addTab directly with QPlainTextEdit, it should fill the available space.
                  In your case with designer, you have to put a layout on the widget that is inside the tab and then the layout the QPlainTextEdit in it.

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

                  M 1 Reply Last reply 26 Jun 2019, 19:54
                  1
                  • S SGaist
                    26 Jun 2019, 17:58

                    That's the thing, you shouldn't need to do anything special. If you call addTab directly with QPlainTextEdit, it should fill the available space.
                    In your case with designer, you have to put a layout on the widget that is inside the tab and then the layout the QPlainTextEdit in it.

                    M Offline
                    M Offline
                    mzimmers
                    wrote on 26 Jun 2019, 19:54 last edited by
                    #9

                    @SGaist very slick.

                    enum LOG_TABS
                    {
                        LOGTAB_HEARTBEAT,
                        LOGTAB_LOGMSG,
                        LOGTAB_BUTTON,
                        LOGTAB_SCAN,
                        NBR_LOGTABS
                    };
                    
                    const QString logtabText[NBR_LOGTABS] =
                    {
                        "Heartbeat Log",
                        "Message Log",
                        "Button Log",
                        "AP Scan Log"
                    };
                    ...
                    QPlainTextEdit m_logTabs[NBR_LOGTABS];
                    for (int i = 0; i < NBR_LOGTABS; ++i)
                    {
                        ui->tabWidget->addTab(&(m_logTabs[i]), logtabText[i]);
                    }
                    

                    (I know I probably should have used QVectors instead of a C array, but hey, I'm mostly a firmware programmer.)

                    I'm curious: what controls the height of the QTabWidget now? Is it the geometry/size policy values of the QTabWidget, or is it the content of the QPlainTextEdits of the tabs? I ask because this implementation causes my QTableView (in another area of the display) to default to a slightly smaller value, and I don't understand why.

                    Thanks!

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 26 Jun 2019, 20:58 last edited by
                      #10

                      Usually, it's the bigger widget added that sets the overall size of the QTabWidget.

                      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

                      1/10

                      24 Jun 2019, 15:49

                      • Login

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