wxStaticText does not resize correctly Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

wxStaticText does not resize correctly

Post by extreme001 »

Hi!

I have a problem try to resize wxStaticText to the size of a wxListCtrl-column. For ech column i created a wxStaticText and set the positions and size of the statictext.

Here's an example:

I resized the first column and then set the width of the underlying wxstatictext to the columnsize....but the wxstatictext was not resized, it's not visible...the position is the same. but if i resize the main window after that, the size and positions are correct. any idea?

Here's the code and an image:

Code: Select all

// inserts a new footer
void CDataView::InsertFooter(int index, wxString sTxtSymbol, int pos,  int type, int alignment)
{
	m_nFootAlign[index] = alignment;
	m_nFootColumn[index] = index;
	m_nFootSymbolPos[index] = pos;
	m_nFootType[index] = type;
	m_sFootSymbol.Add(sTxtSymbol);
	m_lblFooter[index] = new wxStaticText(this, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, alignment);
}

// size and positioning of footers
void CDataView::FitFooters()
{
	int totalwidth = 0, x = 0, colwidth = 0, footpos = 0;
	wxPoint position;
	totalwidth = m_lcData->GetSize().GetWidth();
	for(x=0; x <= (m_lcData->GetColumnCount()-1); x++)
	{
		colwidth = m_lcData->GetColumnWidth(x);
		m_lblFooter[x]->SetLabel(_T("ugag"));
		m_lblFooter[x]->SetSize(colwidth, -1);
		position.x = footpos;
		position.y = m_lcData->GetSize().GetHeight();
		m_lblFooter[x]->SetPosition(position);
		footpos+=colwidth;
	}
}


/*!
 * wxEVT_SIZE event handler for ID_LcData
 */

void CDataView::OnSizeList( wxSizeEvent& event )
{
	
////@begin wxEVT_SIZE event handler for ID_LcData in CDataView.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_SIZE event handler for ID_LcData in CDataView. 
	
	FitFooters();
}




/*!
 * wxEVT_COMMAND_LIST_COL_END_DRAG event handler for ID_LcData
 */

void CDataView::OnLcDataColEndDrag( wxListEvent& event )
{
	
////@begin wxEVT_COMMAND_LIST_COL_END_DRAG event handler for ID_LcData in CDataView.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_COMMAND_LIST_COL_END_DRAG event handler for ID_LcData in CDataView. 

	FitFooters();
	
}
Before resizing:
Image

After resizing the column:

Image

You can see that the position is wrong

so...i resized the mainwindow and it's ok...that's the look i want after resizing the columns:

Image

I hope you understand.

Thank you!
Attachments
After resizing the column
After resizing the column
screen2.jpg (5.49 KiB) Viewed 2488 times
After resizing the main window it's correct
After resizing the main window it's correct
screen3.jpg (7.09 KiB) Viewed 2488 times
the screen
the screen
screen.jpg (6.18 KiB) Viewed 2490 times
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Wild guess : maybe you just need to call refresh()/REpaint() (don't remember the exact name) or Update() after moving labels around?
extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Post by extreme001 »

Hi.

Update() and/or Refresh() does not help.
Are there any other solutions out there?

Thank you!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Could you try printing the coord to which you are moving the text control? Just to make sure the event is actually being caught, and that the control is moved to the right coord at the right time
extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Post by extreme001 »

The event is caught and the coords are also right. I think i have to call resizing-event after calling list-event.

I will try and write a response.

Thank you!!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

I've just come to think about it; moving text widgets manually might not be the best nor the easiest way to go about this; maybe you can just add a panel at the bottom of the list, and draw the labels onto this panel? This way when the list is resized you can just repaint the panel

Otherwise i don't really know what to do about them the way you created them (maybe if you posted a compilable minimal sample?)
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Post by Nelson Joseph »

Hi
Did you try the following?

Code: Select all

wxWindow::DoUpdateWindowUI
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event)
Regards,
Nelson Joseph
extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Post by extreme001 »

Hey wxWidgeters....


Nice to read to read the latest lines. I tried all...and i'm sure i can't manipulate the layout in this case. Every time the columns are resized/resizing in the list i set the new coords for my wxStaticTexts...if the width of the first column is 200... i set the new position so that the wxStaticTexts right is at 200. But.. the new position is not recognized...only after Onsize is called the position is correct.

Tomorrow i can try the new hints worked out by Nelson and Auria and i hope it's working :-)

I'll reply to this thread tomorrow...and thank all for the help.

Please excuse my bad english....
extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Post by extreme001 »

I tried the two mentioned methods but there's still no succes. A very misterious behaviour is it...if i drag a column to set the size slowly the correct size for my footer is set, but if i drag it faster size is not correct. After that i tried to fit the size in the idle event. that works but is not the best way, more a bad way to do it.

Are there more ideas out there?

Thanks.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

could you post a compilable sample? lots of things could be going on, it's hard to tell without testing
extreme001
I live to help wx-kind
I live to help wx-kind
Posts: 192
Joined: Fri Dec 22, 2006 9:17 am
Location: Germany
Contact:

Post by extreme001 »

Hi Auria!

I tried a workaround...if the columns size was manipulated, the new size of list is calculated (by adding each width of the columns) to set the width to whole width of all columns...the thread is here: http://forums.wxwidgets.org/viewtopic.php?t=23010

It's very frustrating...but i'm happy that users want to help :-)

Thank you!
Post Reply