使用位图图像时,wxWidgets 按钮最初不显示

问题描述 投票:0回答:1

我正在将 wxWidgets 用于我正在尝试制作的应用程序,现在此代码中的所有内容在技术上都可以正常工作,图像按预期显示,但是我创建的按钮仅出现在鼠标悬停在它们应该在的位置上之后。任何想法将不胜感激。 :) 解释为什么会发生这种情况也很有用。

#include "MainFrame.h" #include <wx/wx.h> MainFrame::MainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title) { wxPanel* Panel = new wxPanel(this); // creates the panel which the controls will be attached to // forces the size of the frame to remain 800 x 800 as to not mess up any image formatting this->SetClientSize(800, 800); this->SetMinSize(GetSize()); this->SetMaxSize(GetSize()); // image handling wxImage::AddHandler(new wxPNGHandler()); // this adds the images that are required to the panel. wxBitmap ImageBitmap("pathToImage/backgroundfinal.png", wxBITMAP_TYPE_PNG); // this tells the program where to fetch the image file this->SetBackgroundColour("#c2cbc6"); // this sets the background colour of the window to the given hex code wxStaticBitmap* GUIDisplay = new wxStaticBitmap(this, wxID_ANY, ImageBitmap, wxPoint(0, 0));//this positions the image in the frame // fonts wxFont StreakFont(36, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD); // buttons wxButton* TopicQuestion = new wxButton(Panel, wxID_ANY, "Topic Questions", wxPoint(300, 125), wxSize(245, 85)); wxButton* Flashcards = new wxButton(Panel, wxID_ANY, "Flashcards", wxPoint(300, 245), wxSize(245, 85)); wxButton* PopQuiz = new wxButton(Panel, wxID_ANY, "Pop Quiz", wxPoint(300, 365), wxSize(245, 85)); wxButton* Customisation = new wxButton(Panel, wxID_ANY, "Customisation", wxPoint(300, 485), wxSize(245, 85)); wxButton* Leaderboard = new wxButton(Panel, wxID_ANY, "Leaderboard", wxPoint(300, 605), wxSize(245, 85)); // text wxStaticText* DailyStreak = new wxStaticText(this, wxID_ANY, "52", wxPoint(395, 10)); DailyStreak->SetFont(StreakFont); }

	
c++ user-interface wxwidgets
1个回答
0
投票
this

使用了错误的父级(

Panel
而不是
wxStaticBitmap
),因此它与面板重叠而不是位于面板内部。

强烈

建议避免对控件使用绝对位置和大小,而使用调整器进行布局

© www.soinside.com 2019 - 2024. All rights reserved.