#include#include #include #include int main() { Fl_Window win(200, 200, "FrameView Example"); Fl_Frame frame(10, 10, 180, 100); Fl_Button button1(20, 20, 80, 30, "Button 1"); Fl_Button button2(100, 60, 80, 30, "Button 2"); frame.end(); win.end(); win.show(); int totalWidth = frame.contentsWidth(); cout << "Total width of frame contents: " << totalWidth << endl; return Fl::run(); }
#includeThis example creates a QFrame with a QHBoxLayout that contains two QPushButtons. The contentsWidth method is used to get the total width of the QFrame's contents, including both buttons. The package library used in this example is Qt.#include #include int main(int argc, char *argv[]) { QApplication a(argc, argv); QFrame frame; QPushButton button1("Button 1"); QPushButton button2("Button 2"); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(&button1); layout->addWidget(&button2); frame.setLayout(layout); frame.show(); int totalWidth = frame.contentsWidth(); cout << "Total width of frame contents: " << totalWidth << endl; return a.exec(); }