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. Problem with using layouts with custom widgets

Problem with using layouts with custom widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlayoutcustom widgets
2 Posts 2 Posters 897 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.
  • B Offline
    B Offline
    bigThrum
    wrote on 19 Jul 2016, 20:00 last edited by
    #1

    I need to make a custom widget which will contain other custom widgets which are made up of qt QPushbuttons. All use layouts. The final widget does not build correctly, in that only one of the widgets in the final "big_wid" is visible.

    My code is hereunder and I think I am doing something conceptionally silly , but I just cannot see it.

    #include <QApplication>
    #include <QWidget>
    #include <QPushButton>
    #include <QHBoxLayout>
    #include <QVBoxLayout>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QWidget* wid = new QWidget;
    QWidget* wid2 = new QWidget;
    QWidget* big_wid = new QWidget;
    
    //wid->setWindowTitle("My Widget");
    big_wid->setWindowTitle("My Big widget");
    
    QPushButton* pb1 = new QPushButton("PushButton_1");
    QPushButton* pb2 = new QPushButton("PushButton_2");
    QPushButton* pb3 = new QPushButton("PushButton_3");
    
    QHBoxLayout* layout = new QHBoxLayout;
    
    layout->addWidget(pb1);
    layout->addWidget(pb2);
    layout->addWidget(pb3);
    
    wid->setLayout(layout);
    wid2->setLayout(layout);
    
    QVBoxLayout* lay = new QVBoxLayout;
    
    lay->addWidget(wid);
    lay->addWidget(wid2);
    
    big_wid->setLayout(lay);
    
    big_wid->show();
    
    return a.exec();
    

    }

    All help gratefully received.

    K 1 Reply Last reply 19 Jul 2016, 20:07
    0
    • B bigThrum
      19 Jul 2016, 20:00

      I need to make a custom widget which will contain other custom widgets which are made up of qt QPushbuttons. All use layouts. The final widget does not build correctly, in that only one of the widgets in the final "big_wid" is visible.

      My code is hereunder and I think I am doing something conceptionally silly , but I just cannot see it.

      #include <QApplication>
      #include <QWidget>
      #include <QPushButton>
      #include <QHBoxLayout>
      #include <QVBoxLayout>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);

      QWidget* wid = new QWidget;
      QWidget* wid2 = new QWidget;
      QWidget* big_wid = new QWidget;
      
      //wid->setWindowTitle("My Widget");
      big_wid->setWindowTitle("My Big widget");
      
      QPushButton* pb1 = new QPushButton("PushButton_1");
      QPushButton* pb2 = new QPushButton("PushButton_2");
      QPushButton* pb3 = new QPushButton("PushButton_3");
      
      QHBoxLayout* layout = new QHBoxLayout;
      
      layout->addWidget(pb1);
      layout->addWidget(pb2);
      layout->addWidget(pb3);
      
      wid->setLayout(layout);
      wid2->setLayout(layout);
      
      QVBoxLayout* lay = new QVBoxLayout;
      
      lay->addWidget(wid);
      lay->addWidget(wid2);
      
      big_wid->setLayout(lay);
      
      big_wid->show();
      
      return a.exec();
      

      }

      All help gratefully received.

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 19 Jul 2016, 20:07 last edited by
      #2

      @bigThrum
      Hi,

      wid->setLayout(layout);
      wid2->setLayout(layout);
      

      This will not work. You need to have a separate layout object for each of your widgets, and a separate set of QPushButton objects for each of the layouts.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2

      1/2

      19 Jul 2016, 20:00

      • Login

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