August 18, 2011

MFreeM MFreeM
Lab Rat
12 posts

QTabWidget Question

 

Hi All,

I’ve created a widget subclass and added this as a tab onto QTabWidget. My main code below.

  1. int main(int argc, char *argv[])
  2. {
  3.     QApplication a(argc, argv);
  4.     Widget* w = new Widget;
  5.     QTabWidget* desktopUI = new QTabWidget;
  6.     desktopUI->addTab(w, "Test");
  7.     QVBoxLayout* mainLayout = new QVBoxLayout;
  8.     mainLayout->addWidget(desktopUI);
  9.  
  10.  
  11.  
  12.  
  13.     return a.exec();
  14. }

When i run this app. The app default size is half the size of my widget, i’m forced to resize it manually before i can see all widgets on the tab.
For the life of me i cant figure out how to change the default size of the qtabwidget.

Any ideas?

Thanks

3 replies

August 18, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

Hi MFreeM,

what do you use the layout for?
This should be removed.
Aditionally, you don’t call show on the top level widget.

  1. int main(int argc, char *argv[])
  2. {
  3.     QApplication a(argc, argv);
  4.     Widget* w = new Widget;
  5.     QTabWidget* desktopUI = new QTabWidget;
  6.     desktopUI->addTab(w, "Test");
  7.     desktopUI->show();
  8.  
  9.     return a.exec();
  10. }

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

August 18, 2011

rokemoon rokemoon
Lab Rat
197 posts

you don’t need layout manager

  1. int main(int argc, char *argv[])
  2. {
  3.     QApplication a(argc, argv);.
  4.  
  5.     Widget* w = new Widget;
  6.  
  7.     QTabWidget desktopUI;
  8.  
  9.     desktopUI.addTab(w, "Test");
  10.     desktopUI.resize(w->size());
  11.     desktopUI.show();
  12.  
  13. //    QVBoxLayout* mainLayout = new QVBoxLayout;
  14. //    mainLayout->addWidget(desktopUI);
  15.  
  16.     return a.exec();
  17. }

[Edit:] Gerolf faster :-)

August 18, 2011

MFreeM MFreeM
Lab Rat
12 posts

Oh sherbert sorry – i copied and pasted my code without thinking. This was me just playing around to see if i can try and sort the problem.

But i see rokemoon has helped with the size problem..

I’ll try that – thanks!!

 
  ‹‹ [Moved] QtWebKit not responding to mouse events?      QGraphicsView with OpenGL backend ››

You must log in to post a reply. Not a member yet? Register here!