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. Cannot use a custom widget with Qt Designer

Cannot use a custom widget with Qt Designer

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 2 Posters 1.2k 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.
  • P Offline
    P Offline
    PoignardAzur
    wrote on last edited by
    #1

    Here's my problem : I've designed a widget with Qt designer, to open a SQLite file. Its main feature is a QTabWidget : the tab draws the table you get from your query, the second the error messages and other output. I want to use a custom widget in the first tab, but when I try this :
    @m_sqlWidget = new SqlWidget(ui->tab);
    QHBoxLayout* layout = new QHBoxLayout();
    layout->addWidget(m_sqlWidget);
    ui->tab->setLayout(layout);@

    the custom widget (which is basically a QWidget with a QTextEdit in it for now) doesn't draw completely. To be precise, it draws in a small rectangle at the top-left of the tab (so, good position, bad size) and if I write too much stuff in the QTextEdit, you can't see it because it's out of bound.

    My question is : did I use the correct way to add a custom widget to a qt-designer widget ? If not, what should I do instead ? If yes, where does my problem come from ?

    Thanks in advance to everyone answering this :D

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

      Hi and welcome to devnet,

      You are doing things wrong:
      QTabWidget has the addTab method that creates a new tab with your widget in it.

      What you are doing currently is trying to replace the QTabWidget's layout (you might have an error message about that in your console indicating that it failed) with your own.

      Since your SqlWidget has the tab widget as his parent, it will position itself where you see it but won't be handled by the layout since the setLayout probably failed

      Hope it helps

      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
      • P Offline
        P Offline
        PoignardAzur
        wrote on last edited by
        #3

        The parent of my SqlWidget isn't tha QTabWidget, it's the QWidget in QTabWidget's first tab, so I don't really understand the issue.

        But still, I did what you said, and it worked, so thanks a lot :)

        But now I got another quick question : is it possible to change the order of the tabs in the QTabWidget ?

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

          @SqlWidget(ui->tab); // isn't tab the QTabWidget ?@

          You can get the widget with widget(index), removeTab(index) and then insertTab(newIndex, widget, label)

          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