You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

MarkoSan

Intermediate

  • "MarkoSan" is male
  • "MarkoSan" started this thread

Posts: 230

Location: Ljubljana, SI-EU

Occupation: Embedded Systems Engineer I

  • Send private message

1

Saturday, December 24th 2005, 11:10am

Window resizing problem [SOLVED]

How do I achieve so if window is rezised that button stays UNDER THE TABLE?
there is no home like 127.0.0.1 ;)
MS Winidows XP SP2; MS Visual Studio 2005 SP1 with that regresion patch; Qt 4.2.1 Commercial

This post has been edited 2 times, last edit by "MarkoSan" (Dec 26th 2005, 9:37pm)


Michiel

Trainee

  • "Michiel" is male

Posts: 112

Location: The Netherlands

Occupation: Student / Programmer

  • Send private message

2

Saturday, December 24th 2005, 12:47pm

Could you be more specific about what you're trying to do and what you've already tried?

All I can say without this information is: if the button is under the table in a layout, it will stay there, even after resizing.

MarkoSan

Intermediate

  • "MarkoSan" is male
  • "MarkoSan" started this thread

Posts: 230

Location: Ljubljana, SI-EU

Occupation: Embedded Systems Engineer I

  • Send private message

3

Saturday, December 24th 2005, 2:50pm

I have a QDialog class and instance of it, which is parent to some data table and button. I 've setup the layouts so that table lies above button. But If I resize window, tuh button is placed on the left or right side of table, depenging on new size of window. How do I get rid of that??

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//**********************************************************************
// function author: markofr
// function creation date: 19/12/2005
// function purpose: widgets need to be aligned on window
// function name: AlignWidgets()
//***********************************************************************
void CCustomerBrowser::AlignWidgets()
{
    m_pHorizontalLayout=new QHBoxLayout();
    Q_CHECK_PTR(m_pHorizontalLayout);
    m_pVerticalLayout=new QVBoxLayout();
    Q_CHECK_PTR(m_pVerticalLayout);
    
    // pointer checks   
    Q_CHECK_PTR(m_pButtonClose);
    Q_CHECK_PTR(m_pTableView);

    // vertical alignment
    m_pVerticalLayout->addWidget(m_pTableView);
    m_pVerticalLayout->addWidget(m_pButtonClose);

    // horizontal alignment
    m_pHorizontalLayout->addWidget(m_pButtonClose);
    m_pHorizontalLayout->addWidget(m_pTableView); 

    // completing layout
    m_pVerticalLayout->addLayout(m_pHorizontalLayout);
}
//***********************************************************************
// END OF CCustomerBrowser::AlignWidgets()
//***********************************************************************
there is no home like 127.0.0.1 ;)
MS Winidows XP SP2; MS Visual Studio 2005 SP1 with that regresion patch; Qt 4.2.1 Commercial

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

4

Saturday, December 24th 2005, 2:54pm

Don't you think the layout should be applied to the widget? :)

Source code

1
2
3
4
m_pHorizontalLayout=new QHBoxLayout();
    Q_CHECK_PTR(m_pHorizontalLayout);
    m_pVerticalLayout=new QVBoxLayout();
    Q_CHECK_PTR(m_pVerticalLayout);


The above code doesn't achieve that. You create two layouts not associated with the parent widget.

Quoted

From Qt docs:
The simplest use of the class is like this:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
        QWidget *window = new QWidget;
        QPushButton *button1 = new QPushButton("One");
        QPushButton *button2 = new QPushButton("Two");
        QPushButton *button3 = new QPushButton("Three");
        QPushButton *button4 = new QPushButton("Four");
        QPushButton *button5 = new QPushButton("Five");

        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(button1);
        layout->addWidget(button2);
        layout->addWidget(button3);
        layout->addWidget(button4);
        layout->addWidget(button5);

        window->setLayout(layout);
        window->show();


Line 15 applies the layout. You don't have one.

MarkoSan

Intermediate

  • "MarkoSan" is male
  • "MarkoSan" started this thread

Posts: 230

Location: Ljubljana, SI-EU

Occupation: Embedded Systems Engineer I

  • Send private message

5

Saturday, December 24th 2005, 2:55pm

Aarhg!!!!

So the code should be:

Source code

1
2
3
4
m_pHorizontalLayout=new QHBoxLayout(this);
Q_CHECK_PTR(m_pHorizontalLayout);
m_pVerticalLayout=new QVBoxLayout(this);
Q_CHECK_PTR(m_pVerticalLayout)


Am i right?
there is no home like 127.0.0.1 ;)
MS Winidows XP SP2; MS Visual Studio 2005 SP1 with that regresion patch; Qt 4.2.1 Commercial

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

6

Saturday, December 24th 2005, 2:56pm

Try it :) BTW. Can't you use Designer for that?

MarkoSan

Intermediate

  • "MarkoSan" is male
  • "MarkoSan" started this thread

Posts: 230

Location: Ljubljana, SI-EU

Occupation: Embedded Systems Engineer I

  • Send private message

7

Saturday, December 24th 2005, 2:59pm

I tried it and I get assertion failed error!!! WTF is going on? I do not want Designer. I must solve this so I will better understand layouts.
there is no home like 127.0.0.1 ;)
MS Winidows XP SP2; MS Visual Studio 2005 SP1 with that regresion patch; Qt 4.2.1 Commercial

MarkoSan

Intermediate

  • "MarkoSan" is male
  • "MarkoSan" started this thread

Posts: 230

Location: Ljubljana, SI-EU

Occupation: Embedded Systems Engineer I

  • Send private message

8

Saturday, December 24th 2005, 3:16pm

Quoted

Originally posted by wysota
Don't you think the layout should be applied to the widget? :)

Source code

1
2
3
4
m_pHorizontalLayout=new QHBoxLayout();
    Q_CHECK_PTR(m_pHorizontalLayout);
    m_pVerticalLayout=new QVBoxLayout();
    Q_CHECK_PTR(m_pVerticalLayout);


The above code doesn't achieve that. You create two layouts not associated with the parent widget.

Quoted

From Qt docs:
The simplest use of the class is like this:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
        QWidget *window = new QWidget;
        QPushButton *button1 = new QPushButton("One");
        QPushButton *button2 = new QPushButton("Two");
        QPushButton *button3 = new QPushButton("Three");
        QPushButton *button4 = new QPushButton("Four");
        QPushButton *button5 = new QPushButton("Five");

        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(button1);
        layout->addWidget(button2);
        layout->addWidget(button3);
        layout->addWidget(button4);
        layout->addWidget(button5);

        window->setLayout(layout);
        window->show();


Line 15 applies the layout. You don't have one.


I have line 15:

Source code

1
m_pCustomerBrowser->setLayout(m_pCustomerBrowser->GetLayout());

But in other file, mainwindow.cpp:

Source code

1
2
3
4
5
6
7
8
9
void CMainWindow::bwCustomers()
{
    m_pCustomerBrowser=new CCustomerBrowser(this);
    Q_CHECK_PTR(m_pCustomerBrowser);
    m_pWorkspace->addWindow(m_pCustomerBrowser);
    m_pCustomerBrowser->AlignWidgets();
    m_pCustomerBrowser->setLayout(m_pCustomerBrowser->GetLayout());
    m_pCustomerBrowser->showMaximized();
}


And here is the function GetLayout();

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
//***********************************************************************
// function author: markofr
// function creation date: 21/12/2005
// function purpose: returns vertical layout
// function name: GetLayout()
//***********************************************************************
QVBoxLayout* CCustomerBrowser::GetLayout()
{
    return m_pVerticalLayout;
}
//***********************************************************************
// END OF CCustomerBrowser::GetLayout()
//**********************************************************************
there is no home like 127.0.0.1 ;)
MS Winidows XP SP2; MS Visual Studio 2005 SP1 with that regresion patch; Qt 4.2.1 Commercial

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

9

Saturday, December 24th 2005, 3:36pm

Quoted

Originally posted by MarkoSan
I tried it and I get assertion failed error!!! WTF is going on? I do not want Designer. I must solve this so I will better understand layouts.


So make a designer based form, uic it and see the C++ code generated. This is the best way to see how it is done.

BTW. Widgets have a layout() method which retrieves the current widget layout. Your GetLayout() method does practically the same -- why double that?

MarkoSan

Intermediate

  • "MarkoSan" is male
  • "MarkoSan" started this thread

Posts: 230

Location: Ljubljana, SI-EU

Occupation: Embedded Systems Engineer I

  • Send private message

10

Monday, December 26th 2005, 10:14pm

I did it, thanks, now works.
there is no home like 127.0.0.1 ;)
MS Winidows XP SP2; MS Visual Studio 2005 SP1 with that regresion patch; Qt 4.2.1 Commercial