开发者

Connect custom widget to QWidgetTab for sizing

开发者 https://www.devze.com 2022-12-22 04:55 出处:网络
I\'m trying to get every widget to scale with change in window size. I have a main window which has a QTabWidget with a QWidget holder for each tab. I then have a custom widget with a seperate .ui fil

I'm trying to get every widget to scale with change in window size. I have a main window which has a QTabWidget with a QWidget holder for each tab. I then have a custom widget with a seperate .ui file that I set to fill the QWidget space of the tab. The problem is, I can't get the contents of the QWidget to expand, only the tab and QWidget of the main window. Also, I noticed if i change the ui->setupUi( ) argument for the custom widget from "this" to "parent" the problem is fixed, and the custom wi开发者_Python百科dget will scale correctly. The only problem with this is none of the buttons work when I do that. The application output reads out "No Slot" found errors for the buttons. What is the correct way to make this connection?

Edit: Example code

MainWindow:: ...
{
    //assign customWidget to widget placeholder on tabWidget.
    //holder is just a blank widget set in gridLayout on tab widget.
    CustomWidget * customWidget = new CustomWidget(ui->customWidgetHolder);

    setCentralWidget(ui->tabWidget); 
    //This gets the sizing I want with the tabs, but 
    //doesn't  pass it past the customWidgetHolder.
}


From what I undertand, you need to use a layout, for your custom widget inside your tab

    QTabWidget* tabWidget = new QTabWidget();
    QWidget* tab = new QWidget();
    QVBoxLayout* verticalLayout = new QVBoxLayout(tab);

    YourWidget* widget = new YourWidget(tab);
    verticalLayout->addWidget(widget);

    tabWidget->addTab(tab, QString());

But you'll need to be more specific (code sample ?) about the SIGNAL/SLOT connection you've made if you want answer about it.

0

精彩评论

暂无评论...
验证码 换一张
取 消