3

I'm working on little CAD like program for our indie game project. I already have nicely working form with a bunch of widgets and so on. But one thing is bothering me.

I'm using DockWidgets and inside these i have QTableWidget and empty Horizontal layout as container waiting for my OpenGLWindow class that i later initialize and put it into. When i start the app all DockWidgets are set to size of QTableWidget ignoring that the OpenGLWindow was added to the layout when the form instance was created and I have to expand the dock by myself.

So is there any way to tell the dock widget to expand as much as possible?

My OpenGLWindow looks like:

class OpenGLWindow : public QWindow, protected QOpenGLFunctions

And that's how I'm inserting it to the layout on startup:

OpenGLWindow * glwindow = new OpenGLWindow(...);
QWidget * container = QWidget::createWindowContainer(glwindow,ui->dockWidget,Qt::Window);
ui->horizontalLayout->addWidget(container);

I've tried to expand it by many different weird ways and now I'm realy out of ideas.

Thanks for help.

Update: Thats size policy of container:

container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

Update: The main problem is to adjust the QDockWidget to its maximal possible width.

Update: I'm still having same problem, but now new one appeared when I added one more OpenGLWindow sharing context with the previous one. Both container widgets are now little oversized at startup so they overlay the DockWidgets title and when i resize any widget within the main window they just resize to normal size like expected.

Gob
  • 73
  • 2
  • 6
  • What is the sizePolicy of container ? – Manuel Arwed Schmidt Apr 12 '14 at 14:49
  • Added it to the post. – Gob Apr 12 '14 at 14:59
  • Looks fine. Does it got a valid parent() ? It needs to know what dimensions it should expand to :-) QWidget::createWindowContainer(glwindow, yourParent); You might need to make sure that yourParent is having a correct size, too. – Manuel Arwed Schmidt Apr 12 '14 at 15:02
  • I think the problem is that the DockWidget is initialized with tableWidget first and when I later add the Window container it just does not increase the width. – Gob Apr 12 '14 at 15:02
  • I've added as parent the dockWidget now but nothing seems to be changing. :( but good point i didn't set that properly at first – Gob Apr 12 '14 at 15:06
  • Its easier to use QtCreator to create a dummy.ui file to get immediate feedback. My default horizontalLayouts should have a proper size and resizing policys. If you have inited everything from your own C++, I'd also check on that. I have found that such bugs where typically located somewhere in the parent()-chain and not the widget itself. – Manuel Arwed Schmidt Apr 12 '14 at 15:08
  • Oh, another thing that comes to my mind: Do all parents have the Q_OBJECT macro in place ? If thats missing in your .h files, try to add it. Calling QObject() from your Widget's constructor can't harm too. – Manuel Arwed Schmidt Apr 12 '14 at 15:12
  • ook! here comes one newbie question. If I have Class A that inherits from QObject and has Q_OBJECT macro inside and i declare Class B that inherits from class A do i have to put the Q_OBJECT macro inside class B? – Gob Apr 12 '14 at 15:18
  • I'd say yes. The Q_OBJECT macro will implement some basic SLOTS and SIGNALS that are needed for object to object communication. I always added it to any of my Qt-Objects. C++ standard might say it will be derived to childs though. Try it though, if it works you know it was missing the macro or constructor call. You can call their constructor by editing your .h file: class YourObject : public QWindow { YourObject(QObject* parent): QObject(parent); }. Also, what is your parent ? In some cases your cant use the object as a parent, but need to get object->someWidget() from it. – Manuel Arwed Schmidt Apr 12 '14 at 15:24
  • Well at the moment i have One class implemented as I said above the OpenGLWindow and im using its derived class ImporterWindow that also has Q_OBJECT macro inside (added it seconds ago as you told me) and im using createWindowContainer(ImporterWindow,dockWidget,Qt::window) to create container widget. so im passing the DockWidget as parent for importerWindow now. – Gob Apr 12 '14 at 15:31
  • Its hard to debug it without a minimal example. Try adding ImporterWindow(whatever): QWindow(whatever needs to be passed); where QWindow should be whatever is your highest level Qt Stuff you are deriving from. QObject might not be sufficient in some cases, as it is a primite/low level class without much functionality. – Manuel Arwed Schmidt Apr 12 '14 at 15:34
  • Nothing seems to work properly. Do you have any idea how to set dockWidget to its maximal possible width? I'm thinking now of some workaround. – Gob Apr 12 '14 at 15:44
  • 2
    Bloody hell! Thats incredible... i've solved it by simply setting minimumWidth.... it seems like the container was initialized with 0 minimumWidth and Height and somehow it adjusted the height right, but the width not.. I don't know why but i thought i've already tryed that... I'm still confused but happy that we solved it. Thanks for your help dude. You've teached me some new things. :] – Gob Apr 12 '14 at 15:55
  • Good that you have atleast a workaround. But thats a dirty bugfix that won't solve your fundamental problem and e.g. won't allow flexible stuff below minimumWidth.. It would be good to solve that. Qt is a big framework and when things are wrong at some central spot, it will result in more than just one bug later one. I can't help you out anymore, as I can't fiddle with a minimal example. So best keep question open. – Manuel Arwed Schmidt Apr 12 '14 at 15:59
  • Right now i think theres nothing wrong with the container part. Theres just no reaction from DockWidget to its sizePolicy. And the DockWidget is created and configured by Qt Designer not by me in code. – Gob Apr 12 '14 at 16:03

0 Answers0