Cannot use a custom widget with Qt Designer



  • 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


  • Lifetime Qt Champion

    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



  • 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 ?


  • Lifetime Qt Champion

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

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.