@@ -61,6 +61,9 @@ def __init__(self):
61
61
62
62
63
63
self .add_new_tab (QUrl ("https://www.google.com" ), "Página Inicial" ) # Adiciona a primeira guia
64
+ # Após adicionar a primeira aba, garantimos que os botões sejam atualizados
65
+ self .update_buttons_state ()
66
+
64
67
65
68
# Ocultar a barra de status por enquanto (pode ser adicionada depois se necessário)
66
69
self .statusBar ().hide ()
@@ -144,13 +147,22 @@ def update_urlbar(self, q, browser=None):
144
147
def update_buttons_state (self ):
145
148
"""Atualiza o estado (habilitado/desabilitado) dos botões de navegação."""
146
149
browser = self .current_browser ()
147
- # Itera sobre as ações da toolbar para encontrar os botões e atualizar seus estados
150
+ if browser :
151
+ # Acessa o histórico para verificar se pode voltar/avançar
152
+ history = browser .history ()
153
+ can_go_back = history .canGoBack ()
154
+ can_go_forward = history .canGoForward ()
155
+ else :
156
+ # Se não houver navegador, desabilita tudo
157
+ can_go_back = False
158
+ can_go_forward = False
159
+
148
160
for action in self .toolbar .actions ():
149
161
if action .text () == "⬅️ Voltar" :
150
- # Habilita "Voltar" se houver um navegador e puder voltar, e não estiver na página inicial
151
- action .setEnabled (browser is not None and browser . canGoBack () and browser .url () != QUrl ("https://www.google.com" ))
162
+ # Habilita "Voltar" se houver um navegador, puder voltar e não estiver na página inicial
163
+ action .setEnabled (browser is not None and can_go_back and browser .url () != QUrl ("https://www.google.com" ))
152
164
elif action .text () == "➡️ Avançar" :
153
- action .setEnabled (browser is not None and browser . canGoForward () )
165
+ action .setEnabled (browser is not None and can_go_forward )
154
166
elif action .text () == "🔄 Recarregar" :
155
167
action .setEnabled (browser is not None ) # Recarregar sempre que houver um navegador
156
168
elif action .text () == "🏠 Início" :
0 commit comments