I am using PySide2 for GUI. I have a "Rename Project" QAction. The function must be like this:

  1. set enable to false if tab name is "*Untitled" or file is unsaved.
  2. set enable to True if file is loaded.
    How to do this?
  3. Whenever switching to tab, these functions should be observed.
jacklin commented: a +0

I created a method that would look for tab name like this:

def enable_rename():
    if tab_name != '*Untitled":
        self.rename_action.setEnabled(True)
    else:
        self.rename_action.setEnabled(False)

I put this to my initialization part. But this is not working.

That code doesn't look correct to me. I would have expected to read something about PySide.QtGui.QTabBar.tabText(index).
Documentation appears to be at https://srinikom.github.io/pyside-docs/PySide/QtGui/QTabBar.html

This leads me to think you are just beginning to use Pyside which is all well and good but if you are looking for coders you'll have to put up the project requirements and what the pay for the job is.

Read https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question to cover all the other areas of a good question.

@
QMenuBar menuBar;
QMenu
menuFile;
QAction actionOpen;
QAction
actionClose;

menuBar = new QMenuBar(MainWindow);

menuFile = new QMenu(menuBar);
menuFile->setTitle("File");

actionOpen = new QAction(MainWindow);
actionOpen->setText("Open");

actionClose = new QAction(MainWindow);
actionClose->setText("Close");

menuBar->addAction(menuFile->menuAction());
menuFile->addAction(actionOpen);
menuFile->addAction(actionClose);
@

To disable one of the items or whole "File" menu
@
actionOpen->setEnable(false);
menuFile->setEnable(false);
@

To enable them back
@
actionOpen->setEnable(true);
menuFile->setEnable(true);
@

Hi,

I have few QActions added to a QMenu:
ui->menuView->addAction( pAction1 );
ui->menuView->addAction( pAction2 );
ui->menuView->addAction( pAction3 );

My problem is that I can't disable a particular QAction:
pAction2->setDiasbled( true ); // doesn't do anything

In the documentation it is written: "An action will be disabled when all widgets to which it is added (with QWidget::addAction()) are disabled or not visible."
So why it doesn't work makes sense, but it is not what I want.

How can I do it?

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.