Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ wxWidgets - trouble with ScrolledWindow that has no width
    primarykey
    data
    text
    <p>I'm very new to wxWidgets, and C++, but I'm familiar with other toolkits. I wanted a layout like this:</p> <p><img src="https://i.stack.imgur.com/6LBlO.png" alt="My design"></p> <p>and this is what it looks like. It looks as though my window has no width at all:</p> <p><img src="https://i.stack.imgur.com/AhOpC.png" alt="enter image description here"></p> <p>So this is my code, heavily annotated.</p> <p>And here's my code, which I believe is as close to intent as I can get it. The design is this, each "sender", "sent at" and "message" is in a unique block based on a reusable panel:</p> <pre><code>//CONTENTS OF GUI_MESSAGE_ITEM.H #ifndef GUIMESSAGEITEM_H #define GUIMESSAGEITEM_H #include "wx/panel.h" // Base class: wxPanel #include "wx/stattext.h" #include "sms_message.h" #include "wx/window.h" #include "wx/wx.h" class GUIMessageItem : public wxPanel { public: GUIMessageItem(wxWindow* parent, wxWindowID winid, const SMSMessage&amp; smsMessage); ~GUIMessageItem(); private: wxStaticText* stSender; wxStaticText* stSentTime; wxStaticText* stMessageContents; }; #endif // GUIMESSAGEITEM_H //CONTENTS OF GUI_MESSAGE_ITEM.CPP #include "gui_message_item.h" GUIMessageItem::GUIMessageItem(wxWindow* parent, wxWindowID winid, const SMSMessage&amp; smsMessage) : wxPanel(parent, winid), stSender(new wxStaticText(this, winid, smsMessage.GetSender())), stSentTime(new wxStaticText(this, winid, smsMessage.GetSentTime())), stMessageContents(new wxStaticText(this, winid, smsMessage.GetMessage())) { wxColour blue(wxT("#2A2AF7")); wxColour green(wxT("#56DB4F")); wxFont originalFont = stSender-&gt;GetFont(); wxFont boldFont(originalFont); boldFont.SetWeight( wxFONTWEIGHT_BOLD ); wxSize stsMin(100, 60); wxSize bodyMin(300, 100); stSender-&gt;SetForegroundColour(blue); stSentTime-&gt;SetForegroundColour(green); stSender-&gt;SetFont(boldFont); stSentTime-&gt;SetFont(boldFont); stSender-&gt;SetMinSize(stsMin); stSentTime-&gt;SetMinSize(stsMin); stMessageContents-&gt;SetMinSize(bodyMin); stMessageContents-&gt;Wrap(200); wxBoxSizer* lines = new wxBoxSizer( wxVERTICAL ); wxBoxSizer* topLine = new wxBoxSizer( wxHORIZONTAL ); lines-&gt;AddSpacer(4); topLine-&gt;AddSpacer(5); this-&gt;SetSizer(lines); topLine-&gt;Add(stSender, wxALIGN_LEFT); topLine-&gt;Add(stSentTime, wxALIGN_RIGHT); lines-&gt;Add(topLine); lines-&gt;Add(stMessageContents, wxALIGN_CENTER_HORIZONTAL ); lines-&gt;SetMinSize(wxSize(400,400)); this-&gt;FitInside(); this-&gt;Layout(); } GUIMessageItem::~GUIMessageItem() { } //MAIN CODE FOR THE WHOLE FORM MainFrameBase::MainFrameBase( wxWindow* parent, wxWindowID id, const wxString&amp; title, const wxPoint&amp; pos, const wxSize&amp; size, long style ) : wxFrame( parent, id, title, pos, size, style ) { this-&gt;SetSizeHints( wxDefaultSize, wxDefaultSize ); //Menu Bar stuff. m_menuBar = new wxMenuBar( 0 ); m_menuFile = new wxMenu(); wxMenuItem* menuFileExit; menuFileExit = new wxMenuItem( m_menuFile, wxID_EXIT, wxString( _("E&amp;xit") ) + wxT('\t') + wxT("Alt+X"), wxEmptyString, wxITEM_NORMAL ); wxMenuItem* menuFileOpen; menuFileOpen = new wxMenuItem( m_menuFile, wxID_OPEN, wxString( _("&amp;Open") ) + wxT('\t') + wxT("Alt+O"), wxEmptyString, wxITEM_NORMAL ); m_menuFile-&gt;Append( menuFileOpen ); m_menuFile-&gt;Append( menuFileExit ); m_menuBar-&gt;Append( m_menuFile, _("&amp;File") ); this-&gt;SetMenuBar( m_menuBar ); //main sizer for whole interface wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL ); this-&gt;SetSizer( mainSizer ); // Filter box section wxStaticText* filterLabel = new wxStaticText(this, wxID_ANY, wxT("Filter by Sender:")); m_filter = new wxComboBox( this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY ); wxBoxSizer* filterSizer = new wxBoxSizer( wxHORIZONTAL ); filterSizer-&gt;Add(filterLabel); filterSizer-&gt;Add(m_filter); mainSizer-&gt;Add(filterSizer); // List of Messages section //The issue must be here somewhere... m_scrWin = new wxScrolledWindow( this, wxID_ANY ); m_listSizer = new wxBoxSizer(wxVERTICAL); m_scrWin-&gt;SetSizer(m_listSizer); mainSizer-&gt;Add(m_scrWin, wxEXPAND); //m_scrWin should take the WHOLE of the interface. //example msg SMSMessage* exampleMessage = new SMSMessage( wxT("+44 07950 322 789"), wxT("2011-13-07 13:22"), wxT("Yo mate, what's up?") ); for (int i = 0; i &lt; 6; i++) { AddSMSMessagePanel(*exampleMessage); } //wxSize minimum(300,500); m_scrWin-&gt;FitInside(); //Use fit inside to make the scrollwindow use the width of the items inside? without doing this I get no scrollbar at all... //m_scrWin-&gt;SetMinSize(minimum); //m_listSizer-&gt;SetMinSize(minimum); //m_scrWin-&gt;EnableScrolling(true, true); //m_scrWin-&gt;SetScrollRate(1,1); m_scrWin-&gt;SetScrollRate(5, 5); this-&gt;Layout(); m_statusBar = this-&gt;CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY ); this-&gt;Centre( wxBOTH ); // Connect Events this-&gt;Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( MainFrameBase::OnCloseFrame ) ); this-&gt;Connect( menuFileOpen-&gt;GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnFileOpen ) ); this-&gt;Connect( menuFileExit-&gt;GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnExitClick ) ); } void MainFrameBase::AddSMSMessagePanel(const SMSMessage&amp; message) { GUIMessageItem* gmi = new GUIMessageItem(m_scrWin, wxID_ANY, message); //object inherits from wxPanel m_listSizer-&gt;Add(gmi); } </code></pre> <p>I'm sorry to bring such specific questions like this here, but I'm new to C++ and to wxWidgets and I've spent about 5 hours trying to solve this issue already and I don't know what knowledge I lack.</p> <p>This is a link to the complete source code: <a href="https://github.com/PhillipTaylor/SMSReader" rel="nofollow noreferrer">https://github.com/PhillipTaylor/SMSReader</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload