Hello,

I want to extend a "stock" Qt widget with a custom widget.

For example I want to add a additional button to a spinbox.

To archive this i used the public accessible setLayout() function. The result is not what i epected. I want to add the button left or right of the standard QSpinBox.

See this small snippet.


Qt Code:
  1. #include <QApplication>
  2. #include <QHBoxLayout>
  3. #include <QPushButton>
  4. #include <QSpinBox>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QApplication a(argc, argv);
  9.  
  10.  
  11. QHBoxLayout * hbl = new QHBoxLayout();
  12. hbl->addWidget( new QPushButton("Hello"));
  13. s.setLayout(hbl);
  14.  
  15. s.show();
  16.  
  17. return a.exec();
  18. }
To copy to clipboard, switch view to plain text mode 

qt.jpg

In my real code I have extended the "stock" Qt widget and therefore can also access the protected members.

Hoiw can i access the "real" layout of QSpinBox.

Is there another solution to archive my goal?

Greetings Gerd